Search code examples
jsonamazon-web-servicesamazon-s3aws-cloudformationamazon-sqs

Creating Multiple QueueConfigurations in CloudFormation


I'm currently trying to write multiple QueueConfigurations into my CloudFormation template. Each is an SQS queue that is triggered when an object is created to a specified prefix. Here's what I have so far:

{
    "Resources": {
      "S3Bucket": {
        "Type" : "AWS::S3::Bucket",
        "Properties" : 
          "BucketName" : { "Ref" : "paramBucketName" },
          "LoggingConfiguration" : {
            "DestinationBucketName" : "test-bucket",
            "LogFilePrefix" : { "Fn::Join": [ "", [ { "Ref": "paramBucketName" }, "/" ] ] }
          },
          "NotificationConfiguration" : {
              "QueueConfigurations" : [{
                "Id" : "1",
                "Event" : "s3:ObjectCreated:*",
                "Filter" : { 
                  "S3Key" : {
                    "Rules" : {
                      "Name" : "prefix",
                      "Value" : "folder1/"
                    }
                  }
                },
                "Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-cdc_feeder_prod_hvr_dev"
              }],   
              "QueueConfigurations" : [{
                "Id" : "2",
                "Event" : "s3:ObjectCreated:*",
                "Filter" : { 
                  "S3Key" : {
                    "Rules" : {
                      "Name" : "prefix",
                      "Value" : "folder2/"
                    }
                  }
                },
                "Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-latency_hvr_dev"
              }]
            }                               
          }          
        }
      }
    }
  }

I've encountered the error saying Encountered unsupported property Id. I thought that by defining the ID, I would be able to avoid the Duplicate object key error.

Does anyone know how to create multiple triggers in a single CloudFormation template? Thanks for the help in advance.


Solution

  • It should be structured like the below, There should only be one QueueConfigurations attribute that contains all queue configurations within it. Also the Id parameter is not a valid property.

    {
        "Resources": {
          "S3Bucket": {
            "Type" : "AWS::S3::Bucket",
            "Properties" : 
              "BucketName" : { "Ref" : "paramBucketName" },
              "LoggingConfiguration" : {
                "DestinationBucketName" : "test-bucket",
                "LogFilePrefix" : { "Fn::Join": [ "", [ { "Ref": "paramBucketName" }, "/" ] ] }
              },
              "NotificationConfiguration" : {
                  "QueueConfigurations" : [{
                    "Event" : "s3:ObjectCreated:*",
                    "Filter" : { 
                      "S3Key" : {
                        "Rules" : {
                          "Name" : "prefix",
                          "Value" : "folder1/"
                        }
                      }
                    },
                    "Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-cdc_feeder_prod_hvr_dev"
                  },
                  {
                    "Event" : "s3:ObjectCreated:*",
                    "Filter" : { 
                      "S3Key" : {
                        "Rules" : {
                          "Name" : "prefix",
                          "Value" : "folder2/"
                        }
                      }
                    },
                    "Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-latency_hvr_dev"
                  }]
                }                               
              }          
            }
          }
        }
      }
    

    There is more information about QueueConfiguration in the documentation.