Created
June 15, 2024 14:00
-
-
Save proton0210/a2dd7b2959e32ecbafca4710683b5ebe to your computer and use it in GitHub Desktop.
12. proxy Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// StepFunctionsProxy/handler.ts | |
import { StartExecutionCommand, SFNClient } from "@aws-sdk/client-sfn"; | |
const stepFunctions = new SFNClient({}); | |
export const handler = async (event: any) => { | |
console.log(JSON.stringify(event, null, 2)); | |
const orderString = JSON.parse(event.body); | |
console.log({ orderString }); | |
const order = JSON.parse(orderString); | |
console.log({ order }); | |
const input = { | |
order: order, | |
}; | |
const params = { | |
stateMachineArn: process.env.STATE_MACHINE_ARN, | |
input: JSON.stringify(input), | |
}; | |
try { | |
await stepFunctions.send(new StartExecutionCommand(params)); | |
return { | |
statusCode: 200, | |
body: JSON.stringify({ message: "Execution started successfully" }), | |
}; | |
} catch (error) { | |
console.error("Error starting execution:", error); | |
return { | |
statusCode: 500, | |
body: JSON.stringify({ message: "Error starting execution" }), | |
}; | |
} | |
}; | |
--- | |
Construct | |
--- | |
const stepFunctionsProxyLambda = new cdk.aws_lambda_nodejs.NodejsFunction( | |
this, | |
"StepFunctionsProxyFunction", | |
{ | |
entry: path.join(__dirname, "StepFunctionsProxy", "handler.ts"), | |
handler: "handler", | |
runtime: cdk.aws_lambda.Runtime.NODEJS_20_X, | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment