-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Python: Add S3 Batch scenario with CloudFormation integration #7531
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
base: main
Are you sure you want to change the base?
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.
Looks like a good addition, I added some clarification, references to applicable standards, and suggestions.
import boto3 | ||
from botocore.exceptions import ClientError, WaiterError | ||
|
||
class CloudFormationHelper: |
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.
These classes would be more consistent with the other examples if they were separate files. See the coding standards for more information.
""" | ||
try: | ||
# Define the CloudFormation template | ||
template = { |
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.
Could this stack be defined in a separate file? See some of our other examples, such as directory buckets, for a sample of what this might look like.
ClientError: If bucket creation fails | ||
""" | ||
try: | ||
if self.region_name != 'us-east-1': |
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 might include some comments as to why the region specification changes the parameters.
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.
isn't the insertion of CreateBucketConfiguration
handled internally by the client?
DASHES = "-" * 80 | ||
STACK_NAME = "MyS3Stack" | ||
|
||
def __init__(self, region_name='us-west-2'): |
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.
If there's not a reason, we don't usually hard-cod regions.
|
||
|
||
class TestCloudFormationHelper: | ||
"""Test cases for CloudFormationHelper class.""" |
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.
Have a look at some of the existing scenarios tests, like ECR, to see how we use stubbers for our tests. Unit tests are used for logic testing, otherwise we use a stubber (with option to use a real client) to run the scenario with mocked user input.
def create_s3_batch_job(self, account_id, role_arn, manifest_location, | ||
report_bucket_name): | ||
""" | ||
Create an S3 batch operation job. |
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 can tag these discrete actions for inclusion in the actions part of the code library. See the Java example for the snippet blocks.
'Outputs': [ | ||
{'OutputKey': 'S3BatchRoleArn', 'OutputValue': 'arn:aws:iam::123456789012:role/test-role'} | ||
] | ||
}] |
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.
indentation looks short on this line
ClientError: If bucket creation fails | ||
""" | ||
try: | ||
if self.region_name != 'us-east-1': |
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.
isn't the insertion of CreateBucketConfiguration
handled internally by the client?
@aBurmeseDev is this ready for re-review? |
This PR adds code example that demonstrates how to use the AWS SDK for Python (boto3) to work with S3 Batch Operations. The scenario covers various operations such as creating an AWS Batch compute environment, creating a job queue, creating a job definition, and submitting a job.
The example includes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.