Skip to content

Commit 8840d6c

Browse files
Fix idempotency with S3 buckets
1 parent ab1e1be commit 8840d6c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tests/aws/scenario/test_bookstore.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import aws_cdk.aws_opensearchservice as opensearch
1515
import pytest
1616
from aws_cdk.aws_lambda_event_sources import DynamoEventSource
17+
from botocore.exceptions import ClientError
1718
from constructs import Construct
1819

1920
from localstack.testing.pytest import markers
@@ -155,7 +156,7 @@ def infrastructure(self, aws_client, patch_opensearch_strategy):
155156
yield prov
156157

157158
@markers.aws.validated
158-
def test_setup(self, aws_client, infrastructure, snapshot, cleanups, s3_create_bucket):
159+
def test_setup(self, aws_client, infrastructure, snapshot, cleanups):
159160
if infrastructure.skipped_provisioning:
160161
pytest.skip("setup only running once")
161162

@@ -164,7 +165,11 @@ def test_setup(self, aws_client, infrastructure, snapshot, cleanups, s3_create_b
164165

165166
# pre-fill dynamodb
166167
# json-data is from https://aws-bookstore-demo.s3.amazonaws.com/data/books.json
167-
s3_create_bucket(Bucket=S3_BUCKET_BOOKS_INIT)
168+
try:
169+
create_s3_bucket(bucket_name=S3_BUCKET_BOOKS_INIT, s3_client=aws_client.s3)
170+
except ClientError as exc:
171+
if exc.response["Error"]["Code"] != "BucketAlreadyOwnedByYou":
172+
raise exc
168173
cleanups.append(
169174
lambda: cleanup_s3_bucket(
170175
aws_client.s3, bucket_name=S3_BUCKET_BOOKS_INIT, delete_bucket=True

0 commit comments

Comments
 (0)