-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Added explicit check for a bucket when deploying a stack #6171
Conversation
There was a problem hiding this 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:
localstack/tests/integration/test_cloudformation.py
Lines 262 to 281 in 0a4359f
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:
localstack/tests/integration/test_cloudformation.py
Lines 1004 to 1006 in 0a4359f
stack = deploy_cfn_template( | |
template=TEST_TEMPLATE_17 % (queue_name, bucket_name, queue_arn), | |
) |
There was a problem hiding this 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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a stronger check 👍
@whummer I parametrized the test as you suggested. However, since the issue does not appear for the default region |
f64916e
to
07e43a4
Compare
There was a problem hiding this 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 :-)
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Introduced a fixture to get clients for a specific region
9be5379
to
bf002bd
Compare
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 outsideus-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.