0
votes

I have created a simple AWS state machine with lambda functions. Like below

{
  "Comment":"Validates data",
  "StartAt": "ChooseDocumentType",
  "States": {
    "ChooseDocumentType": {      
      "Type": "Choice",
      "Choices":[
        {
          "Variable":"$.documentType",
          "StringEquals":"RETURN",
          "Next":"ValidateReturn"
        },
        {
          "Variable":"$.documentType",
          "StringEquals":"ASSESSMENT",
          "Next":"ValidateAssessment"
        }        
      ],
      "Default":"DefaultState"
    },
    "ValidateReturn":{
      "Type":"Task",
      "Resource":"arn:aws:lambda:us-west-2:111111111:function:ValidateReturn",
      "Next":"DefaultState"
    },
     "ValidateAssessment":{
      "Type":"Task",
      "Resource":"arn:aws:lambda:us-west-2:111111111:function:ValidateAssessment",
      "Next":"DefaultState"
    },
    "DefaultState":{
      "Type":"Pass",      
      "End":true
    }
  }
}

Questions
1> How do i create stages for this state machine. (like production, development etc)?

2>Each lambda function has alias pointing to different versions. So development alias always point to $latest version and production alias point to, lets say, version 2. How do i dynamically associate state machine's stages with these lambda alias? So state machine in development stage should use lambda function with alias development and so on.

I am using AWS console to manage state machines and lambdas, and i don't see any action to create stages for state machine

2

2 Answers

0
votes

You can declare the alias and the version in the Lambda ARN:

# default, $LATEST
arn:aws:lambda:us-west-2:111111111:function:ValidateAssessment

# using alias
arn:aws:lambda:us-west-2:111111111:function:ValidateAssessment:development

# using version
arn:aws:lambda:us-west-2:111111111:function:ValidateAssessment:2

Use these in the Step Function definition according to your needs.

0
votes

Re: # 2, if your main concern is controlling which Lambda alias gets invoked, there is a way you can do that via a single step function.

Your step function state definition would be something like:

{  
   "Type": "Task",
   "Resource": "arn:aws:states:::lambda:invoke",
   "Parameters": {  
      "InvocationType": "RequestResponse",
      "FunctionName": "someFunction",
      "Qualifier.$": "$.lambdaAlias",
      "Payload": {}
   },
}

So where you execute the step function and would specify the stage if there was such a thing, you'd pass a lambdaAlias parameter. (There's nothing magical about that name, you can pull it from whatever step function input parameter you want.)

The request payload to your Lambda would go in Parameters.Payload.

https://docs.aws.amazon.com/step-functions/latest/dg/connect-lambda.html