Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added explicit check for a bucket when deploying a stack #6171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 1, 2022

Conversation

giograno
Copy link
Member

Issue coming from support.
The problem came from the fact that we consider a resource as not created if it does not have notification configs attached.
This causes a BucketAlreadyOwnedByYou error outside us-east-1.
I changed the deploy template with a function that explicitly checks if the bucket exists and, if not, proceeds to create it.
Feedback are welcome, quite a newbie here on CloudFormation.

@giograno giograno temporarily deployed to localstack-ext-tests May 30, 2022 22:29 Inactive
@github-actions
Copy link

github-actions bot commented May 30, 2022

LocalStack integration with Pro

       3 files  ±0         3 suites  ±0   1h 9m 30s ⏱️ + 6m 2s
1 071 tests +1  1 038 ✔️ +1  33 💤 ±0  0 ±0 
1 369 runs  +1  1 309 ✔️ +1  60 💤 ±0  0 ±0 

Results for commit bf002bd. ± Comparison against base commit 932733d.

♻️ This comment has been updated with latest results.

@giograno giograno assigned whummer and unassigned whummer May 31, 2022
@giograno giograno marked this pull request as ready for review May 31, 2022 00:50
@giograno giograno requested a review from thrau as a code owner May 31, 2022 00:50
Copy link
Member

@whummer whummer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great set of changes @giograno ! 👍

We could try to cover this with a small test. For example, we already have a small test template with S3 NotificationConfiguration here:

TEST_TEMPLATE_17 = """
AWSTemplateFormatVersion: 2010-09-09
Resources:
TestQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: %s
ReceiveMessageWaitTimeSeconds: 0
VisibilityTimeout: 30
MessageRetentionPeriod: 1209600
TestBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: %s
NotificationConfiguration:
QueueConfigurations:
- Event: s3:ObjectCreated:*
Queue: %s
"""

So we could parameterize this test with a flag whether to create the bucket before deploying the stack:

stack = deploy_cfn_template(
template=TEST_TEMPLATE_17 % (queue_name, bucket_name, queue_arn),
)

Copy link
Member

@dominikschubert dominikschubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🪣 🚀 , minor exception handling nit

bucket_name = props.get("BucketName")
try:
s3_client.head_bucket(Bucket=bucket_name)
except Exception:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: too broad. we should probably explicitly check for it being a not found exception here and avoid swallowing any unrelated issues here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a stronger check 👍

@giograno giograno temporarily deployed to localstack-ext-tests May 31, 2022 13:55 Inactive
@github-actions github-actions bot added the tests label May 31, 2022
@giograno
Copy link
Member Author

giograno commented May 31, 2022

@whummer I parametrized the test as you suggested. However, since the issue does not appear for the default region us-east-1, I added also a small fixture to patch the default region_name when we create a client. Does this sound like a viable approach? cc @dominikschubert

@giograno giograno force-pushed the explicit-bucket-name-check-cloudformation-create branch from f64916e to 07e43a4 Compare May 31, 2022 16:30
@giograno giograno temporarily deployed to localstack-ext-tests May 31, 2022 16:30 Inactive
@giograno giograno temporarily deployed to localstack-ext-tests June 1, 2022 14:12 Inactive
@github-actions github-actions bot removed the tests label Jun 1, 2022
Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thanks for jumping on this. i don't know much about CFN but implementation looks good :-)

@giograno
Copy link
Member Author

giograno commented Jun 1, 2022

Simplified the test a bit, as discussed with @whummer. Actually, we don't even need to have a specific region backend with the CloudFormation client to replicate the bug, given the global name space for S3 buckets.

Copy link
Member

@whummer whummer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@giograno giograno force-pushed the explicit-bucket-name-check-cloudformation-create branch from 9be5379 to bf002bd Compare June 1, 2022 14:51
@giograno giograno temporarily deployed to localstack-ext-tests June 1, 2022 14:52 Inactive
@giograno giograno merged commit f47969a into master Jun 1, 2022
@giograno giograno deleted the explicit-bucket-name-check-cloudformation-create branch June 1, 2022 16:24
@github-actions github-actions bot locked and limited conversation to collaborators Jun 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants