Skip to content

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

aBurmeseDev
Copy link

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:

  • CloudFormation integration for IAM role creation
  • S3 bucket and object management
  • S3 Batch job creation and monitoring
  • Comprehensive unit tests with mocking

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the Python This issue relates to the AWS SDK for Python (boto3) label Jul 22, 2025
@brmur brmur added the Feature Scenario A simple code example to show how certain tasks can be accomplished using several services and SDKs. label Jul 23, 2025
Copy link
Contributor

@rlhagerm rlhagerm left a 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.

@rlhagerm
Copy link
Contributor

rlhagerm commented Aug 7, 2025

@aBurmeseDev is this ready for re-review?

@aBurmeseDev aBurmeseDev requested a review from rlhagerm August 14, 2025 16:23
Copy link
Contributor

@rlhagerm rlhagerm left a comment

Choose a reason for hiding this comment

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

@aBurmeseDev , this is looking really close now - only a few questions and small issues here, once those are resolved and I can successfully run the scenario and tests, I'll approve it.

excerpts:
- description: Learn S3 Batch Basics Scenario.
snippet_tags:
- python.example_code.s3control.Batch.scenario
Copy link
Contributor

Choose a reason for hiding this comment

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

This tag doesn't seem to exist in the code.

excerpts:
- description:
snippet_tags:
- python.example_code.s3control.update_job_status
Copy link
Contributor

Choose a reason for hiding this comment

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

This tag doesn't seem to exist in the code.

To run this workflow, pull AWS tokens and run the command below:

```bash
python s3_batch.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be s3_batch_scenario.py now?


## Additional resources

- [Amazon S3 Developer Guide](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock.html)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is linking to an object-lock page, did you mean to link to something for S3 Batch?

print("\n" + self.DASHES)
print("3. Cancel the S3 Batch job")
cancel_job = q.ask("Do you want to cancel the Batch job? (y/n): ", q.is_yesno)
if cancel_job:
Copy link
Contributor

Choose a reason for hiding this comment

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

If I choose y here, I get an error and am unable to continue the scenario. Does that happen for you?

self.cfn_helper.destroy_cloudformation_stack(self.STACK_NAME)

except Exception as e:
print(f"An error occurred: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

If the scenario fails, we should try to clean up whatever exists: bucket, stack, etc.

import pytest
from moto import mock_s3, mock_s3control, mock_sts

from test_s3_batch_stubber import S3BatchStubber
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to put the stubber in test_tools, and then add an import for it. Take a look at the test setup for the conditional_requests scenario. You may then want to run the tests from a higher directory, or let me know how you're running them so I can verify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Scenario A simple code example to show how certain tasks can be accomplished using several services and SDKs. Python This issue relates to the AWS SDK for Python (boto3)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants