Skip to content

Instantly share code, notes, and snippets.

@toddlers
Created January 7, 2021 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddlers/0b51e843b0fb815d8d3f230e25c42d84 to your computer and use it in GitHub Desktop.
Save toddlers/0b51e843b0fb815d8d3f230e25c42d84 to your computer and use it in GitHub Desktop.
intrinsic functions
{
"Comment": "A Catch example of the Amazon States Language using an AWS Lambda Function",
"StartAt": "nextstep",
"States": {
"nextstep": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-central-1:1234567890:function:catcherror",
"Parameters": {
"executionId.$": "States.Format('somestring {}', $$.Execution.Id)"
},
"End": true
}
}
}
@toddlers
Copy link
Author

toddlers commented Jan 7, 2021

corresponding output from function

{'executionId': 'somestring arn:aws:states:eu-central-1: 1234567890:execution:Catchfailure:2e7a5795-1d12-7a50-936c-47d8fbaf301d'}

In this what you are looking for like a random string , that too is not returned by $$.Execution.Id. So would be good to use a lambda to generate the string and use that for further States.Format

@toddlers
Copy link
Author

toddlers commented Jan 7, 2021

{
  "Comment": "A Catch example of the Amazon States Language using an AWS Lambda Function",
  "StartAt": "nextstep",
  "States": {
    "nextstep": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:eu-central-1: 1234567890:function:catcherror",
      "ResultPath": "$.randomstring",
      "Parameters": {
        "executionId.$": "States.Format('somestring {}', $$.Execution.Id)"
      },
      "End": true
    }
  }
}

outputs execution id by parsing arn:aws:states:eu-central-1: 1234567890:execution:Catchfailure:2e7a5795-1d12-7a50-936c-47d8fbaf301d

Screen Shot 2021-01-07 at 1 29 38 PM

@toddlers
Copy link
Author

toddlers commented Jan 7, 2021

{
  "Comment": "A Catch example of the Amazon States Language using an AWS Lambda Function",
  "StartAt": "nextstep",
  "States": {
    "nextstep": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:eu-central-1: 1234567890:function:catcherror",
      "ResultPath": "$.randomstring",
      "Parameters": {
        "executionId.$": "States.Format('somestring {}', $$.Execution.Id)"
      },
      "Next": "Pass"
    },
    "Pass": {
      "Type": "Pass",
      "OutputPath": "$.randomstring",
      "End": true
    }
  }
}

output :

Screen Shot 2021-01-07 at 1 43 13 PM

@toddlers
Copy link
Author

{
  "Comment": "A Catch example of the Amazon States Language using an AWS Lambda Function",
  "StartAt": "nextstep",
  "States": {
    "nextstep": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:eu-central-1:1234567890:function:catcherror",
      "ResultPath": "$.randomstring",
      "Parameters": {
        "executionName.$": "$$.Execution.Name"
      },
      "Next": "PassRandomeString"
    },
    "PassRandomeString": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:eu-central-1: 1234567890:function:mytestfunction",
      "Parameters": {
        "randomstring.$": "$.randomstring"
      },
      "End": true
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment