Skip to content

Commit

Permalink
Merge pull request pulumi#1044 from pulumi/lambda-callback-update
Browse files Browse the repository at this point in the history
Update TS Step Functions to use Callback Functions Instead of Serverless Functions
  • Loading branch information
phillipedwards committed Jul 19, 2021
2 parents 70d1d08 + 75adedb commit 8cf1188
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions aws-ts-stepfunctions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,63 @@ import * as pulumi from "@pulumi/pulumi";
const region = aws.config.requireRegion();

const lambdaRole = new aws.iam.Role("lambdaRole", {
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "lambda.amazonaws.com" }),
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "lambda.amazonaws.com" }),
});

const lambdaRolePolicy = new aws.iam.RolePolicy("lambdaRolePolicy", {
role: lambdaRole.id,
policy: {
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
],
Resource: "arn:aws:logs:*:*:*",
}],
},
role: lambdaRole.id,
policy: {
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
],
Resource: "arn:aws:logs:*:*:*",
}],
},
});

const sfnRole = new aws.iam.Role("sfnRole", {
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: `states.${region}.amazonaws.com` }),
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: `states.${region}.amazonaws.com` }),
});

const sfnRolePolicy = new aws.iam.RolePolicy("sfnRolePolicy", {
role: sfnRole.id,
policy: {
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: [
"lambda:InvokeFunction",
],
Resource: "*",
}],
},
role: sfnRole.id,
policy: {
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: [
"lambda:InvokeFunction",
],
Resource: "*",
}],
},
});

const helloFunction = new aws.serverless.Function(
"helloFunction",
{ role: lambdaRole },
(event, context, callback) => {
callback(null, "Hello");
},
);
const helloFunction = new aws.lambda.CallbackFunction(
"helloFunction", {
role: lambdaRole,
callback: (event, context, callback) => {
callback(null, "Hello");
},
});

const worldFunction = new aws.serverless.Function(
"worldFunction",
{role: lambdaRole},
(event, context, callback) => {
const worldFunction = new aws.lambda.CallbackFunction(
"worldFunction", {
role: lambdaRole,
callback: (event, context, callback) => {
callback(null, `${event} World!`);
},
);
});

const stateMachine = new aws.sfn.StateMachine("stateMachine", {
roleArn: sfnRole.arn,
definition: pulumi.all([helloFunction.lambda.arn, worldFunction.lambda.arn])
.apply(([helloArn, worldArn]) => {
roleArn: sfnRole.arn,
definition: pulumi.all([helloFunction.arn, worldFunction.arn])
.apply(([helloArn, worldArn]) => {
return JSON.stringify({
"Comment": "A Hello World example of the Amazon States Language using two AWS Lambda Functions",
"StartAt": "Hello",
Expand Down

0 comments on commit 8cf1188

Please sign in to comment.