1

I would like to give myself the ability to rollback the Lambda that my SQS events trigger if I ship bad code.

To do this, I would like my SQS event configuration in serverless.yml to apply to a specific lambda version rather than the default $LATEST. I want to “pin” a specific version of a lambda that events trigger to.

Is this possible? Basically I’d like to be able to do something like

myLambda:
    handler: src/handler.myLambda
    events:
      - sqs:
        arn: arn:my:sqs:queue
        targetVersion: 12 <-- Specific Lambda Version that the event configuration applies to
        batchSize: 100
        maximumBatchingWindow: 30

I don’t see something like this mentioned anywhere in the Serverless event docs, but this is so critical it has to exist - right?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Nick
  • 49
  • 4
  • I have a similar problem. were you able to resolve it ? – CyberPunk Jan 20 '23 at 15:05
  • @CyberPunk I don’t think it’s possible to do this :/ I ended up creating a “dev” and a “prod” environment by using the serverless stage and region arguments in the deploy command – Nick Jan 21 '23 at 18:44

1 Answers1

0

You can create an event source mapping with lambda with SQS as the event source. From the docs:

FunctionName
The name of the Lambda function.

FunctionName
The name of the Lambda function.

Name formats
Function name – MyFunction.

Function ARN – arn:aws:lambda:us-west-2:123456789012:function:MyFunction.

Version or Alias ARN – arn:aws:lambda:us-west-2:123456789012:function:MyFunction:PROD.

Partial ARN – 123456789012:function:MyFunction.

The length constraint applies only to the full ARN. If you specify only the function name, it's limited to 64 characters in length.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 140.

Pattern: (arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}(-gov)?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-_]+)(:(\$LATEST|[a-zA-Z0-9-_]+))?

Required: Yes

link to doc: https://docs.aws.amazon.com/lambda/latest/dg/API_CreateEventSourceMapping.html

so in function name you can pin it down to a specific version

CyberPunk
  • 1,297
  • 5
  • 18
  • 35