pulumi-aws icon indicating copy to clipboard operation
pulumi-aws copied to clipboard

Add notification configuration to SQS Queue Python Example is Incorrect

Open estenrye opened this issue 2 years ago • 2 comments

File: themes/default/content/registry/packages/aws/api-docs/s3/bucketnotification/_index.md

Section: Add notification configuration to SQS Queue

The python example for setting up an S3 notification to an SQS queue does not work. The inline queue policy results in the policy authorizing sqs:SendMessage to a non-existent Queue.

The example should be replaced with:

import pulumi
import pulumi_aws as aws

bucket = aws.s3.BucketV2("bucket")
queue = aws.sqs.Queue("queue")

policy = pulumi.Output.all(queue_arn=queue.arn, source_arn=bucket.arn).apply(lambda args: f"""{{
    "Version": "2012-10-17",
    "Statement": [{{
        "Effect": "Allow",
        "Principal": "*",
        "Action": "sqs:SendMessage",
        "Resource": "{ args['queue_arn'] }",
        "Condition": {{
            "ArnEquals": {{
                "aws:SourceArn": "{ args['source_arn'] }"
            }}
        }}
    }}]
}}
"""
queue_policy = aws.sqs.Queue_Policy("queue_policy", queue_url=queue.id, policy=policy)

bucket_notification = aws.s3.BucketNotification("bucketNotification",
    bucket=bucket.id,
    queues=[aws.s3.BucketNotificationQueueArgs(
        queue_arn=queue.arn,
        events=["s3:ObjectCreated:*"],
        filter_suffix=".log",
    )])

estenrye avatar Mar 31 '22 03:03 estenrye

This is derived from this example: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_notification#add-notification-configuration-to-sqs-queue

It works in the original because it hard codes the name of the resource in the policy. We by default apply autonaming, but in this case that breaks the code.

We will need to either:

  1. Not autoname in this case (not clear how we could decide that though)
  2. Change the example in our fork to be in the style noted in the suggestion above

lukehoban avatar Apr 01 '22 12:04 lukehoban

Moving as this will likely need to be addressed in the provider (or upstream fork).

lukehoban avatar Apr 01 '22 12:04 lukehoban