skip to Main Content

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

2

Answers


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

    Login or Signup to reply.
  2. You can do this Using EventBridge Pipes. It has worked for me!

    EventBridge Pipes was announced in Reinvent 2022

    EventBridge Pipes provides a simpler, consistent, and cost-effective way to create point-to-point integrations between event producers and consumers, expanding the EventBridge offering beyond event buses and scheduling.

    The source will be SQS and Target will be Lambda.

    Earlier this was not possible without Eventbridge pipes but now it is. You can take a look at various sources and target for eventbridge pipes

    Just extend this to your CFn template: Cloudformation EventBridge Docs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search