-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/bin/ | ||
/node_modules/ | ||
/.pulumi/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: stepfunctions | ||
description: Basic example of AWS Step Functions with AWS Native | ||
runtime: nodejs |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new) | ||
|
||
# AWS Step Functions | ||
|
||
A basic example that demonstrates using AWS Step Functions with a Lambda function using the AWS Native provider. | ||
|
||
``` | ||
# Create and configure a new stack | ||
$ pulumi stack init stepfunctions-dev | ||
$ export AWS_REGION=us-east-2 | ||
# Install dependencies | ||
$ npm install | ||
# Preview and run the deployment | ||
$ pulumi up | ||
# Start execution using the AWS CLI (or from the console at https://console.aws.amazon.com/states) | ||
$ aws stepfunctions start-sync-execution --state-machine-arn $(pulumi stack output stateMachineArn) | ||
# Remove the app | ||
$ pulumi destroy | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2021, Pulumi Corporation. All rights reserved. | ||
|
||
import * as aws from "@pulumi/aws"; | ||
import * as awsnative from "@pulumi/aws-native"; | ||
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" }), | ||
}); | ||
|
||
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:*:*:*", | ||
}], | ||
}, | ||
}); | ||
|
||
const helloFunction = new awsnative.lambda.Function('helloFunction', | ||
{ | ||
role: lambdaRole.arn, | ||
runtime: "nodejs14.x", | ||
handler: "index.handler", | ||
code: { | ||
zipFile: `exports.handler = function(event, context, callback){ | ||
const response = {"response": "Hello "}; | ||
callback(null, response); | ||
};`, | ||
}, | ||
}, { dependsOn: lambdaRolePolicy }); | ||
|
||
const worldFunction = new awsnative.lambda.Function('worldFunction', | ||
{ | ||
role: lambdaRole.arn, | ||
runtime: "nodejs14.x", | ||
handler: "index.handler", | ||
code: { | ||
zipFile: `exports.handler = function(event, context, callback){ | ||
var response = event.response; | ||
const updated = { "response": response + "World!" }; | ||
callback(null, updated); | ||
};`, | ||
}, | ||
}, {dependsOn: lambdaRolePolicy}); | ||
|
||
|
||
const sfnRole = new aws.iam.Role("sfnRole", { | ||
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: "*", | ||
}], | ||
}, | ||
}); | ||
|
||
const stateMachine = new awsnative.stepfunctions.StateMachine("stateMachine", { | ||
roleArn: sfnRole.arn, | ||
stateMachineType: 'EXPRESS', | ||
definitionString: 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", | ||
"States": { | ||
"Hello": { | ||
"Type": "Task", | ||
"Resource": helloArn, | ||
"Next": "World", | ||
}, | ||
"World": { | ||
"Type": "Task", | ||
"Resource": worldArn, | ||
"End": true, | ||
}, | ||
}, | ||
}); | ||
}), | ||
}, { dependsOn: sfnRolePolicy }); | ||
|
||
export const stateMachineArn = stateMachine.id; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "stepfunctions", | ||
"devDependencies": { | ||
"@types/node": "^8.0.0" | ||
}, | ||
"dependencies": { | ||
"@pulumi/aws": "^4.0.0", | ||
"@pulumi/pulumi": "^3.0.0", | ||
"@pulumi/aws-native": "^0.1.0" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |