Skip to content

Instantly share code, notes, and snippets.

@proton0210
Created June 15, 2024 14:00
Show Gist options
  • Save proton0210/a2dd7b2959e32ecbafca4710683b5ebe to your computer and use it in GitHub Desktop.
Save proton0210/a2dd7b2959e32ecbafca4710683b5ebe to your computer and use it in GitHub Desktop.
12. proxy Function
// 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