-2

I have created a SQS from AWS SAM template.yaml which will return me the SQS path which is required by a lambda function to send message to. Now since the SQS path will be generated during the time of CFT stack creation, how can I use it beforehand or is there a way to use the dynamic SQS path ?

Not able to figure out please help.

1 Answers1

0

As others have pointed out, adding more details will help in getting better answers. Nevertheless, assuming that you are creating an SQS using the below template,

  myQueueLogicalId:
    Type: AWS::SQS::Queue
    Properties: 
      QueueName: myQueue
      VisibilityTimeout: 4200
      MessageRetentionPeriod: 1209600

you can get the queue name (or if you want the full url or ARN change the attribute as given in the sqs cloudformation documentation) to your lambda function by passing it in the environment variable as below:

  myFunctionLogicalId:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
        Variables:
          MY_SQS: !GetAtt 
                      - myQueueLogicalId
                      - QueueName
      FunctionName: myFunction
      Handler: src/handlers/handler
      Runtime: nodejs14.x
      Timeout: 650
      MemorySize: 4096

This parameter can be retrieved in your code as mentioned here.

user11666461
  • 761
  • 7
  • 12