Add AWS-native stepfunction example
ADD
aws-native-ts-stepfunctions/.gitignore
+/bin/
+/node_modules/
+/.pulumi/

ADD
aws-native-ts-stepfunctions/Pulumi.yaml
+name: stepfunctions
+description: Basic example of AWS Step Functions with AWS Native
+runtime: nodejs

ADD
aws-native-ts-stepfunctions/index.ts
+// Copyright 2016-2021, Pulumi Corporation.
+
+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;

ADD
aws-native-ts-stepfunctions/package.json
+{
+ "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"
+ }
+}

ADD
aws-native-ts-stepfunctions/tsconfig.json
+{
+ "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"
+ ]
+}

Add AWS-native stepfunction example (#1087)

Co-authored-by: Levi Blackstone <levi@pulumi.com>