-
Notifications
You must be signed in to change notification settings - Fork 881
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example of AWS StepFunctions in Python (#97)
- Loading branch information
Showing
6 changed files
with
125 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 @@ | ||
name: stepfunctions-py | ||
description: Basic example of AWS Step Functions in Python. | ||
runtime: python |
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,21 @@ | ||
# AWS Step Functions (Python) | ||
|
||
A basic example that demonstrates using AWS Step Functions with a Lambda function, written in Python. | ||
|
||
``` | ||
# Install dependencies | ||
$ pip install -r ./requirements.txt | ||
# Create and configure a new stack | ||
$ pulumi stack init stepfunctions-dev | ||
$ pulumi config set aws:region us-east-2 | ||
# Preview and run the deployment | ||
$ pulumi update | ||
# Start execution using the AWS CLI (or from the console at https://console.aws.amazon.com/states) | ||
$ aws stepfunctions start-execution --state-machine-arn $(pulumi stack output state_machine_arn) | ||
# Remove the app and its stack | ||
$ pulumi destroy && pulumi stack rm -y | ||
``` |
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,31 @@ | ||
# Copyright 2016-2018, Pulumi Corporation. All rights reserved. | ||
|
||
import iam | ||
import pulumi | ||
from pulumi_aws import lambda_, sfn | ||
|
||
hello_world_fn = lambda_.Function('helloWorldFunction', | ||
role=iam.lambda_role.arn, | ||
runtime="python2.7", | ||
handler="hello_step.hello", | ||
code=pulumi.AssetArchive({ | ||
'.': pulumi.FileArchive('./step_hello') | ||
}) | ||
) | ||
|
||
state_defn = state_machine = sfn.StateMachine('stateMachine', | ||
role_arn=iam.sfn_role.arn, | ||
definition="""{ | ||
"Comment": "A Hello World example of the Amazon States Language using an AWS Lambda Function", | ||
"StartAt": "HelloWorld", | ||
"States": { | ||
"HelloWorld": { | ||
"Type": "Task", | ||
"Resource": "%s", | ||
"End": true | ||
} | ||
} | ||
}""" % hello_world_fn.arn | ||
) | ||
|
||
pulumi.output('state_machine_arn', state_machine.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,66 @@ | ||
# Copyright 2016-2018, Pulumi Corporation. All rights reserved. | ||
|
||
from pulumi_aws import config, iam | ||
|
||
lambda_role = iam.Role('lambdaRole', | ||
assume_role_policy="""{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
}, | ||
"Effect": "Allow", | ||
"Sid": "" | ||
} | ||
] | ||
}""" | ||
) | ||
|
||
lambda_role_policy = iam.RolePolicy('lambdaRolePolicy', | ||
role=lambda_role.id, | ||
policy="""{ | ||
"Version": "2012-10-17", | ||
"Statement": [{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
], | ||
"Resource": "arn:aws:logs:*:*:*" | ||
}] | ||
}""" | ||
) | ||
|
||
sfn_role = iam.Role('sfnRole', | ||
assume_role_policy="""{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "states.%s.amazonaws.com" | ||
}, | ||
"Action": "sts:AssumeRole" | ||
} | ||
] | ||
}""" % config.region | ||
) | ||
|
||
sfn_role_policy = iam.RolePolicy('sfnRolePolicy', | ||
role=sfn_role.id, | ||
policy="""{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"lambda:InvokeFunction" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
}""" | ||
) |
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,2 @@ | ||
pulumi>=0.14.0 | ||
pulumi-aws>=0.14.3 |
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,2 @@ | ||
def handler(event, context): | ||
return "Hello world!" |