Skip to content

Commit

Permalink
Merge pull request #246 from andrestoll/externalize-asl-to-json
Browse files Browse the repository at this point in the history
Externalize ASL as JSON file
  • Loading branch information
alexcasalboni authored Apr 30, 2024
2 parents 61acc54 + e6a42a2 commit cf03cf2
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 95 deletions.
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

0 comments on commit cf03cf2

Please sign in to comment.