Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Externalize ASL as JSON file #246

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions statemachine/statemachine.asl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"Comment": "AWS Lambda Power Tuning state machine",
"StartAt": "Initializer",
"States": {
"Initializer": {
"Type": "Task",
"Resource": "${initializerArn}",
"Next": "Branching",
"ResultPath": "$.powerValues",
"TimeoutSeconds": ${totalExecutionTimeout},
"Catch": [
{
"ErrorEquals": ["States.ALL"],
"Next": "CleanUpOnError",
"ResultPath": "$.error"
}
]
},
"Branching": {
"Type": "Map",
"Next": "Cleaner",
"ItemsPath": "$.powerValues",
"ResultPath": "$.stats",
"ItemSelector": {
"input.$": "$",
"value.$": "$$.Map.Item.Value"
},
"MaxConcurrency": 0,
"Catch": [
{
"ErrorEquals": ["States.ALL"],
"Next": "CleanUpOnError",
"ResultPath": "$.error"
}
],
"Iterator": {
"StartAt": "Executor",
"States": {
"Executor": {
"Type": "Task",
"Resource": "${executorArn}",
"End": true,
"TimeoutSeconds": ${totalExecutionTimeout},
"Retry": [{
"ErrorEquals": [
"States.ALL"
],
"IntervalSeconds": 3,
"MaxAttempts": 2
}]
}
}
}
},
"Cleaner": {
"Type": "Task",
"Next": "Analyzer",
"ResultPath": null,
"TimeoutSeconds": ${totalExecutionTimeout},
"Resource": "${cleanerArn}"
},
"Analyzer": {
"Type": "Task",
"Resource": "${analyzerArn}",
"ResultPath": "$.analysis",
"TimeoutSeconds": 10,
"Next": "Optimizer"
},
"Optimizer": {
"Type": "Task",
"Resource": "${optimizerArn}",
"ResultPath": null,
"OutputPath": "$.analysis",
"TimeoutSeconds": ${totalExecutionTimeout},
"End": true
},
"CleanUpOnError": {
"Type": "Task",
"ResultPath": null,
"OutputPath": null,
"Resource": "${cleanerArn}",
"TimeoutSeconds": ${totalExecutionTimeout},
"End": true
}
}
}
109 changes: 14 additions & 95 deletions template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Metadata:
SemanticVersion: 4.3.4
SourceCodeUrl: https://github.com/alexcasalboni/aws-lambda-power-tuning

Parameters:
PowerValues:
Parameters:
PowerValues:
Type: List<Number>
Default: 128,256,512,1024,1536,3008
Description: Default RAM values, used only if not provided as execution input (comma-separated).
Expand Down Expand Up @@ -267,104 +267,23 @@ Resources:
Action: sts:AssumeRole

powerTuningStateMachine:
Type: AWS::StepFunctions::StateMachine
Type: AWS::Serverless::StateMachine
Properties:
StateMachineName:
Name:
Fn::Join:
- '-'
- - !Ref stateMachineNamePrefix
- !Select [2, !Split ['/', !Ref AWS::StackId]]
RoleArn: !GetAtt statemachineRole.Arn
DefinitionString:
!Sub
- '
{
"Comment": "AWS Lambda Power Tuning state machine",
"StartAt": "Initializer",
"States": {
"Initializer": {
"Type": "Task",
"Resource": "${initializerArn}",
"Next": "Branching",
"ResultPath": "$.powerValues",
"TimeoutSeconds": ${totalExecutionTimeout},
"Catch": [{
"ErrorEquals": [ "States.ALL" ],
"Next": "CleanUpOnError",
"ResultPath": "$.error"
}]
},
"Branching": {
"Type": "Map",
"Next": "Cleaner",
"ItemsPath": "$.powerValues",
"ResultPath": "$.stats",
"ItemSelector": {
"input.$": "$",
"value.$": "$$.Map.Item.Value"
},
"MaxConcurrency": 0,
"Catch": [{
"ErrorEquals": ["States.ALL"],
"Next": "CleanUpOnError",
"ResultPath": "$.error"
}],
"Iterator": {
"StartAt": "Executor",
"States": {
"Executor": {
"Type": "Task",
"Resource": "${executorArn}",
"End": true,
"TimeoutSeconds": ${totalExecutionTimeout},
"Retry": [{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 3,
"MaxAttempts": 2
}]
}
}
}
},
"Cleaner": {
"Type": "Task",
"Next": "Analyzer",
"ResultPath": null,
"TimeoutSeconds": ${totalExecutionTimeout},
"Resource": "${cleanerArn}"
},
"Analyzer": {
"Type": "Task",
"Resource": "${analyzerArn}",
"ResultPath": "$.analysis",
"TimeoutSeconds": 10,
"Next": "Optimizer"
},
"Optimizer": {
"Type": "Task",
"Resource": "${optimizerArn}",
"ResultPath": null,
"OutputPath": "$.analysis",
"TimeoutSeconds": ${totalExecutionTimeout},
"End": true
},
"CleanUpOnError": {
"Type": "Task",
"ResultPath": null,
"OutputPath": null,
"Resource": "${cleanerArn}",
"TimeoutSeconds": ${totalExecutionTimeout},
"End": true
}
}
}'
- initializerArn: !GetAtt initializer.Arn
executorArn: !GetAtt executor.Arn
cleanerArn: !GetAtt cleaner.Arn
analyzerArn: !GetAtt analyzer.Arn
optimizerArn: !GetAtt optimizer.Arn
totalExecutionTimeout: !Ref totalExecutionTimeout
Role: !GetAtt statemachineRole.Arn
DefinitionUri: statemachine/statemachine.asl.json
DefinitionSubstitutions:
initializerArn: !GetAtt initializer.Arn
executorArn: !GetAtt executor.Arn
cleanerArn: !GetAtt cleaner.Arn
analyzerArn: !GetAtt analyzer.Arn
optimizerArn: !GetAtt optimizer.Arn
totalExecutionTimeout: !Ref totalExecutionTimeout

Outputs:
StateMachineARN:
Value: !Ref powerTuningStateMachine
Value: !Ref powerTuningStateMachine
Loading