From e6a42a20f6780c7dfd2e6d72fddf6c98ff9ea42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Stoll?= Date: Mon, 22 Apr 2024 14:15:49 +0200 Subject: [PATCH] Externalize ASL as JSON file --- statemachine/statemachine.asl.json | 86 +++++++++++++++++++++++ template.yml | 109 ++++------------------------- 2 files changed, 100 insertions(+), 95 deletions(-) create mode 100644 statemachine/statemachine.asl.json diff --git a/statemachine/statemachine.asl.json b/statemachine/statemachine.asl.json new file mode 100644 index 0000000..30fb230 --- /dev/null +++ b/statemachine/statemachine.asl.json @@ -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 + } + } +} \ No newline at end of file diff --git a/template.yml b/template.yml index c79a745..4c240fb 100644 --- a/template.yml +++ b/template.yml @@ -15,8 +15,8 @@ Metadata: SemanticVersion: 4.3.4 SourceCodeUrl: https://github.com/alexcasalboni/aws-lambda-power-tuning -Parameters: - PowerValues: +Parameters: + PowerValues: Type: List Default: 128,256,512,1024,1536,3008 Description: Default RAM values, used only if not provided as execution input (comma-separated). @@ -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 \ No newline at end of file