How to use references to point for a SQS?

Hello folks!

I’m writing a lambda function that should be triggered when SQS receive a message. It’s working but I’m trying to avoid write sqs names like I did on lambda declaration:

resources:
  Resources:
    WaitingSQS:
      Type: AWS::SQS::Queue   
       Properties:
         QueueName: ${self:provider.environment.WAITING_QUEUE}

functions:
  consumerCallbackQueue:
    handler: src/consumer_callback_queue.handler
    description: Consume SQS callback queue
    events:
      - sqs: arn:aws:sqs:us-east-1:XXXXXXXX:waiting-dev  

My SQS queue is being created by serverless and I would like to write the event using references instead “arn:aws:sqs:us-east-1:XXXXXXXX:waiting-dev”.

Is possible to use references instead what I did?

You can use Fn::GetAtt to return the ARN for a queue.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html

1 Like

It won’t work.
I’ve changed my code to use Fn::GetAtt but still not working:

  consumerCallbackQueue:
    handler: src/consumer_callback_queue.handler
    description: Consume SQS callback queue
      events:
        - sqs: { "Fn::GetAtt" : ["WaitingSQS", "Arn"]}

If I replace sqs attribute value with string arn:aws:sqs:us-east-1:XXXXXXXX:waiting-dev, it works like a charm.

Also, I’ve print { "Fn::GetAtt" : ["WaitingSQS", "Arn"]} using environment variable and looks correct but I have no idea on whats wrong.

Any idea? @buggy

Fixed.

I was trying to update resources instead of run sls remove and a sls deploy. After that I run sls remove, it works like a charm :slight_smile:

Thx

1 Like