How do I create a parameter store configuration value with Serverless Framework?

Viewed 1840

I have the following queue that is getting created with the serverless.yml file of Serverless Framework project:

resources:
  Resources:
    myAppSQSQueue:
      Type: "AWS::SQS::Queue"
      Properties:
        QueueName: "my-app-sqs-queue-${opt:stage, self:provider.stage}"

How do I take URL of the queue that gets created and store it as a parameter in AWS Systems Manager? I need to store it there so other applications outside of this one know how to access it.

1 Answers

I figured it out. Since serverless framework extends CloudFormation, I found the answer in the Cloud Formation documenation here:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-parameter.html

It can be done as follows:

resources:
  Resources:
    myAppSQSQueue:
      Type: "AWS::SQS::Queue"
      Properties:
        QueueName: "my-app-sqs-queue-${opt:stage, self:provider.stage}"
    myAppSSMParameterQueueName:
      Type: AWS::SSM::Parameter
      Properties:
        Name: /${opt:stage, self:provider.stage}/sqs/my-app-param-name
        Type: String
        Value: 
          Fn::GetAtt:
            - myAppSQSQueue
            - Arn
        Tags:
          Environment: ${opt:stage, self:provider.stage}

This stores the ARN of the queue in the parameter store. I'm not sure if getting the url is possible, but the ARN is fine for my use case.

Related