Search code examples
amazon-web-servicesaws-lambdaamazon-sqsaws-event-bridge

SQS triggering AWS Lambda function using CloudFormation


I have a requirement to trigger an AWS Lambda function when there some process pushes the message to Amazon SQS. I have following CloudFormation configuration. The other process is able to push the message to SQS but it is not triggering the Lambda function.

TestFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: abc/xxx/
      Handler: com.test.TestHandler::handleRequest
      Runtime: java11
      MemorySize: 512
      Timeout: 120
      FunctionName: !Join [ "-", [ !Ref TestPrefix, "TestFunction" ] ]
      Role: !Ref LambdaIAMRole
      VpcConfig:
        SecurityGroupIds:
          - !Ref TestSecurityGroupId
        SubnetIds: !Ref TestSubnetIds
      Events:
        MySQSEvent:
          Type: SQS
          Properties:
            Queue: !GetAtt TestQueue.Arn
            BatchSize: 1


TestQueue:
  Type: AWS::SQS::Queue
  Properties:
    QueueName: !Ref TestQueueName
    Enabled: true
    MessageRetentionPeriod: 300
    VisibilityTimeout: 900

Solution

  • You cannot trigger a lambda function directly from SQS. You need to create an Event Source Mapping.