#SQS Queues

In the following example, we specify that the compute function should be triggered whenever there are messages in the given SQS Queue.

The ARN for the queue can be specified as a string, the reference to the ARN of a resource by logical ID, or the import of an ARN that was exported by a different service or CloudFormation stack.

Note: The sqs event will hook up your existing SQS Queue to a Lambda function. Serverless won't create a new queue for you.

functions:
  compute:
    handler: handler.compute
    events:
      # These are all possible formats
      - sqs: arn:aws:sqs:region:XXXXXX:MyFirstQueue
      - sqs:
          arn:
            Fn::GetAtt:
              - MySecondQueue
              - Arn
      - sqs:
          arn:
            Fn::ImportValue: MyExportedQueueArnId
      - sqs:
          arn:
            Fn::Join:
              - ':'
              - - arn
                - aws
                - sqs
                - Ref: AWS::Region
                - Ref: AWS::AccountId
                - MyOtherQueue

#Setting the BatchSize

For the SQS event integration, you can set the batchSize, which effects how many SQS messages can be included in a single Lambda invocation. The default batchSize is 10, and the max batchSize is 10.

functions:
  compute:
    handler: handler.compute
    events:
      - sqs:
          arn: arn:aws:sqs:region:XXXXXX:myQueue
          batchSize: 10
          maximumRetryAttempts: 2

#Setting the MaximumRetryAttempts

This configuration sets up the maximum number of times to retry when the function returns an error.

Note: Serverless only sets this property if you explicitly add it to the sqs configuration (see example below).

Related AWS documentation

Note: The sqs event will hook up your existing sqs to a Lambda function. Serverless won't create a new sqs for you.

functions:
  compute:
    handler: handler.compute
    events:
      - sqs:
          arn: arn:aws:sqs:region:XXXXXX:stream/foo
          batchSize: 10
          maximumRetryAttempts: 10

#IAM Permissions

The Serverless Framework will automatically configure the most minimal set of IAM permissions for you. However you can still add additional permissions if you need to. Read the official AWS documentation for more information about IAM Permissions for SQS events.

Have questions?

Head over to the forums to search for your questions and issues or post a new one.