AWS Step Functions with the AWS Native Provider
A basic example that demonstrates using AWS Step Functions with a Lambda function using the AWS Native provider.
Note: Some resources are not yet supported by the Native AWS provider, so we are using both the Native and Classic provider in this example. The resources will be updated to use native resources as they are available in AWS’s Cloud Control API.
On the first update, you may see the following error message:
error: operation CREATE failed with "InvalidRequest": The role defined for the function cannot be assumed by Lambda. (Service: Lambda, Status Code: 400, Request ID: c33fdd39-59d4-4ba8-8ad6-29f6c04d79eb, Extended Request ID: null)
Re-running the update should succeed. This issue is tracked here
Deploying and running the program
Note: some values in this example will be different from run to run. These values are indicated
Create a new stack:
$ pulumi stack init dev
Set the AWS region:
Either using an environment variable
$ export AWS_REGION=us-west-2
Or with the stack config
$ pulumi config set aws:region us-west-2 $ pulumi config set aws-native:region us-west-2
Restore NPM modules via
pulumi upto preview and deploy changes. After the preview is shown you will be prompted if you want to continue or not.
$ pulumi up Previewing update (dev) ... Updating (dev) View Live: https://app.pulumi.com/***/stepfunctions/dev/updates/1 Type Name Status + pulumi:pulumi:Stack stepfunctions-dev created + ├─ aws:iam:Role sfnRole created + ├─ aws:iam:Role lambdaRole created + ├─ aws:iam:RolePolicy sfnRolePolicy created + ├─ aws:iam:RolePolicy lambdaRolePolicy created + ├─ aws-native:lambda:Function helloFunction created + ├─ aws-native:lambda:Function worldFunction created + └─ aws-native:stepfunctions:StateMachine stateMachine created Outputs: + stateMachineArn: "arn:aws:states:us-west-2:***:stateMachine:***" Resources: + 10 created Duration: ***
To see the resources that were created, run
pulumi stack output:
$ pulumi stack output Current stack outputs (1): OUTPUT VALUE stateMachineArn arn:aws:states:us-west-2:***:stateMachine:***
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)
To clean up resources, run
pulumi destroyand answer the confirmation question at the prompt.