-
Notifications
You must be signed in to change notification settings - Fork 82
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
try to create AP every time, catch if already exists #1609
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.
some nits and a question
s3_client.attach_access_point_policy( | ||
access_point_name=self.access_point_name, policy=json.dumps(access_point_policy) | ||
) | ||
|
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.
why do we need this now and didn't need it previously?
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.
This is in case AP is not yet created. Before the retry part was in creation of of AP
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.
I would explicitly encapsulate the Retry mechanism in the create_bucket_access_point
to ensure that all calls to it return when the bucket is created.
For example something like the below....
def create_bucket_access_point(self, bucket_name: str, access_point_name: str):
try:
self._client.create_access_point(AccountId=self._account_id, Name=access_point_name, Bucket=bucket_name)
except self._client.exceptions.AccessPointAlreadyOwnedByYou:
...
except Exception as e:
log.exception(f'S3 bucket access point creation failed for location {bucket_name=}')
raise e
return Retrying(
retry_on_exception=(self._client.exceptions.NotFoundException,),
stop_max_attempt_number=5,
wait_random_min=1000,
wait_random_max=3000,
).call(self.get_bucket_access_point_arn, access_point_name)['AccessPointArn']
Also you must make sure that you wait enough time. Previous code was waiting for 300secs++, yours wait from 5 to 15 seconds.
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.
Won't it lead us to the same error? If get_access_point_arn will fail, we again receive the problem of Negative Cash?
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.
also, there is no self._client.exceptions.AccessPointAlreadyOwnedByYou:
so, I have to check the string
from itertools import count | ||
|
||
from retrying import Retrying |
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.
unused
return self.try_get_bucket_access_point_arn(bucket_name, access_point_name) | ||
|
||
def try_get_bucket_access_point_arn(self, bucket_name: str, access_point_name: str): | ||
for attempt in range(5): |
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.
you could use @retry(retry_on_result=lambda arn: arn is None, stop_max_attempt_number=10, wait_fixed=30000)
Feature or Bugfix
Detail
Relates
Security
Please answer the questions below briefly where applicable, or write
N/A
. Based onOWASP 10.
fetching data from storage outside the application (e.g. a database, an S3 bucket)?
eval
or similar functions are used?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.