Skip to content

Commit

Permalink
Merge branch 'main' into ATO-807
Browse files Browse the repository at this point in the history
  • Loading branch information
kalpaitch authored Aug 8, 2024
2 parents 127fb0e + e7bedb9 commit aac7fc8
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 161 deletions.
4 changes: 2 additions & 2 deletions backend/api/api.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ Conditions:

Globals:
Function:
Timeout: 10
Runtime: nodejs20.x
Timeout: 15
Runtime: nodejs18.x
PermissionsBoundary: !If [ UsePermissionsBoundary, !Ref PermissionsBoundary, !Ref AWS::NoValue ]
VpcConfig:
SecurityGroupIds: [ !ImportValue VPC-VPCEndpointsSecurityGroup ]
Expand Down
3 changes: 1 addition & 2 deletions backend/api/src/handlers/step-functions/new-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import {APIGatewayProxyEvent, APIGatewayProxyResult, Context} from "aws-lambda";
import {stepFunctionHandler} from "./step-function-handler";

export const newClientHandler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
console.info("In newClientHandler() callback from step function. Context (" + JSON.stringify(context) + ")");
return stepFunctionHandler(event);
return stepFunctionHandler(event, context);
};
3 changes: 1 addition & 2 deletions backend/api/src/handlers/step-functions/new-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import {APIGatewayProxyEvent, APIGatewayProxyResult, Context} from "aws-lambda";
import {stepFunctionHandler} from "./step-function-handler";

export const newServiceHandler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
console.info("In newServiceHandler() callback from step function. Context (" + JSON.stringify(context) + ")");
return stepFunctionHandler(event);
return stepFunctionHandler(event, context);
};
16 changes: 12 additions & 4 deletions backend/api/src/handlers/step-functions/step-function-handler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import {SFNClient, StartSyncExecutionCommand, SyncExecutionStatus} from "@aws-sdk/client-sfn";
import {APIGatewayProxyEvent, APIGatewayProxyResult} from "aws-lambda";
import {APIGatewayProxyEvent, APIGatewayProxyResult, Context} from "aws-lambda";
import * as process from "process";
import {Logger} from "@aws-lambda-powertools/logger";

export const logger = new Logger({
serviceName: "self-service-experience"
});

const stepFunctionsClient = new SFNClient({region: "eu-west-2"});

export const stepFunctionHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
export const stepFunctionHandler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
logger.addContext(context);
logger.info("Starting step function.");

const payload = event?.body ? JSON.parse(event.body as string) : event;
const stateMachineArn = process.env.STATE_MACHINE_ARN as string;
const input = JSON.stringify(payload);
Expand All @@ -23,11 +31,11 @@ export const stepFunctionHandler = async (event: APIGatewayProxyEvent): Promise<
} else if (result.status == SyncExecutionStatus.TIMED_OUT) {
statusCode = 408;
resultBody = "Function timed out";
console.error(resultBody);
logger.error(resultBody);
} else {
statusCode = 400;
resultBody = "Function returned error: " + result.error + ", cause: " + result.cause;
console.error(resultBody);
logger.error(resultBody);
}

return {statusCode: statusCode, body: resultBody};
Expand Down
3 changes: 1 addition & 2 deletions backend/api/src/handlers/step-functions/update-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import {APIGatewayProxyEvent, APIGatewayProxyResult, Context} from "aws-lambda";
import {stepFunctionHandler} from "./step-function-handler";

export const doUpdateClientHandler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
console.info("In doUpdateClientHandler() callback from step function. Context (" + JSON.stringify(context) + ")");
return stepFunctionHandler(event);
return stepFunctionHandler(event, context);
};
3 changes: 1 addition & 2 deletions backend/api/src/handlers/step-functions/update-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import {APIGatewayProxyEvent, APIGatewayProxyResult, Context} from "aws-lambda";
import {stepFunctionHandler} from "./step-function-handler";

export const doUpdateServiceHandler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
console.info("In doUpdateServiceHandler() callback from step function. Context (" + JSON.stringify(context) + ")");
return stepFunctionHandler(event);
return stepFunctionHandler(event, context);
};
Loading

0 comments on commit aac7fc8

Please sign in to comment.