AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)

Example Snippet: SQS, CloudWatch, and SNS

This example adds an Amazon SQS queue and an alarm on queue depth to the environment. The properties that you see in this example are the minimum required properties that you must set for each of these resources. You can download the example at SQS, SNS, and CloudWatch.


This example creates AWS resources, which you may be charged for. For more information about AWS pricing, go to Some services are part of the AWS Free Usage Tier. If you are a new customer, you may test drive these services for free. Go to for more information.

To use this example, do the following:

  1. Create an .ebextensions directory in the top-level directory of your source bundle.

  2. Create two configuration files with the .config extension and place them in your .ebextensions directory. One configuration file defines the resources, and the other configuration file defines the options.

  3. Deploy your application to Elastic Beanstalk.

    YAML relies on consistent indentation. Match the indentation level when replacing content in an example configuration file and make sure that your text editor uses spaces, not tab characters, to indent.

Create a configuration file (e.g., sqs.config) that defines the resources. In this example, we create an SQS queue and define the VisbilityTimeout property in the MySQSQueue resource. Next, we create an SNS Topic and specify that email gets sent to when the alarm is fired. Finally, we create a CloudWatch alarm if the queue grows beyond 10 messages. In the Dimensions property, we specify the name of the dimension and the value representing the dimension measurement. We use Fn::GetAtt to return the value of QueueName from MySQSQueue.

#This sample requires you to create a separate configuration file to define the custom options for the SNS topic and SQS queue.
    Type: AWS::SQS::Queue
          OptionName: VisibilityTimeout
          DefaultValue: 30
    Type: AWS::SNS::Topic
        - Endpoint:
              OptionName: AlarmEmail
              DefaultValue: ""
          Protocol: email
    Type: AWS::CloudWatch::Alarm
      AlarmDescription: "Alarm if queue depth grows beyond 10 messages"
      Namespace: "AWS/SQS"
      MetricName: ApproximateNumberOfMessagesVisible
        - Name: QueueName
          Value : { "Fn::GetAtt" : [ "MySQSQueue", "QueueName"] }
      Statistic: Sum
      Period: 300
      EvaluationPeriods: 1
      Threshold: 10
      ComparisonOperator: GreaterThanThreshold
        - Ref: AlarmTopic
        - Ref: AlarmTopic

Outputs :
    Description : "URL of newly created SQS Queue"
    Value : { Ref : "MySQSQueue" }
  QueueARN :
    Description : "ARN of newly created SQS Queue"
    Value : { "Fn::GetAtt" : [ "MySQSQueue", "Arn"]}
  QueueName :
    Description : "Name newly created SQS Queue"
    Value : { "Fn::GetAtt" : [ "MySQSQueue", "QueueName"]}

For more information about the resources used in this example configuration file, see the following references:

Create a separate configuration file called options.config and define the custom option settings.

     VisibilityTimeout : 30
     AlarmEmail : ""

These lines tell Elastic Beanstalk to get the values for the VisibilityTimeout and Subscription Endpoint properties from the VisibilityTimeout and Subscription Endpoint values in a config file (options.config in our example) that contains an option_settings section with an aws:elasticbeanstalk:customoption section that contains a name-value pair that contains the actual value to use. In the example above, this means 30 and "" would be used for the values. For more information about Fn::GetOptionSetting, see Functions