Skip to content

Commit 8e55c8d

Browse files
committed
move basics_scenarios folder into scenarios
1 parent 3d8a603 commit 8e55c8d

File tree

30 files changed

+3233
-2
lines changed

30 files changed

+3233
-2
lines changed

javav2/example_code/ecr/src/main/java/com/example/ecr/scenario/ECRScenario.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* this Java program will not successfully run. For more information including how to create the local
2828
* image, see:
2929
*
30-
* /getting_started_scenarios/ecr_scenario/README
30+
* /scenarios/basics/ecr/README
3131
*
3232
*/
3333
public class ECRScenario {

kotlin/services/ecr/src/main/kotlin/com/example/ecr/scenario/ECRScenario.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import java.util.Scanner
2323
* this program will not successfully run. For more information including how to create the local
2424
* image, see:
2525
*
26-
* /getting_started_scenarios/ecr_scenario/README
26+
* /scenarios/basics/ecr/README
2727
*
2828
*/
2929

scenarios/basics/batch/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# AWS Batch Service Basic Scenario
2+
3+
## Overview
4+
5+
This AWS Batch Service basic scenario demonstrates how to interact with the AWS Batch service using an AWS SDK. The scenario covers various operations such as creating an AWS Batch compute environment, creating a job queue, creating a job defination, and submitting a job, and so on.
6+
7+
Here are the top six service operations this scenario covers.
8+
9+
1. **Create an AWS Batch computer environment**: Creates an AWS Batch computer environment.
10+
11+
2. **Sets up a job queue**: Creates a job queue that will manage the submission of jobs.
12+
13+
3. **Creates a job definition**: Creates a job definition that specifies how the jobs should be executed.
14+
15+
4. **Registers a Job Definition**: Registers a job definition making it available for job submissions.
16+
17+
5. **Submits a Batch Job**: Submits a job.
18+
19+
6. **Checks the status of the job**: Checks the status of the job.
20+
21+
Note: These steps are not the complete program, but summarizes the 5-6 high-level steps. See the Eng Spec for a complete listing of ECR operations.
22+
23+
### Resources
24+
25+
The basic scenario requires an IAM role that has AWS Batch permissions. A CloudFormation template is used to create the IAM role.
26+
27+
28+
## Implementations
29+
30+
This scenario example is implemented in the following language:
31+
32+
- Java
33+
34+
35+
## Additional reading
36+
37+
- [AWS Batch](https://docs.aws.amazon.com/batch/latest/userguide/what-is-batch.html)
38+
39+
---
40+
41+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0
Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
# AWS Batch Service Scenario Specification
2+
3+
## Overview
4+
This SDK Basics scenario demonstrates how to interact with AWS Batch using the AWS SDK. It demonstrates various tasks such as creating a compute environment, setting up a job queue, defining a job definition, submitting a job, and so on. Finally this scenario demonstrates how to clean up resources. Its purpose is to demonstrate how to get up and running with AWS Batch and the AWS SDK.
5+
6+
## Resources
7+
The required resources for this Basics scenario are two IAM roles. The IAM roles must have permission to interact with the AWS Batch service. This Basics scenario uses a CloudFormation template to create the IAM roles and delete the IAM roles at the end of the program.
8+
9+
This scenario submits a job that pulls a Docker image from Amazon ECR to Amazon Fargate. To place a Docker image on Amazon ECR, run the follow Basics scenario. See [Amazon ECR code examples for the SDK for Java 2.x](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/ecr)
10+
11+
## Hello AWS Batch
12+
This program is intended for users not familiar with the AWS Batch SDK to easily get up and running. The logic is to show use of `listJobsPaginator()`.
13+
14+
## Scenario Program Flow
15+
The AWS Batch Basics scenario executes the following operations.
16+
17+
**Creates two IAM roles using a CloudFormation template**
18+
19+
This operation uses AWS CloudFormation to create two IAM roles that are required for AWS Batch operations. The first role is for the compute environment and grants the necessary permissions for the instances to perform tasks such as reading from Amazon S3 or writing logs to CloudWatch. The second role is for the AWS Batch service to interact with other AWS services.
20+
21+
**Creates a Batch compute environment**
22+
23+
This operation sets up a compute environment where AWS Batch jobs will be executed. The compute environment is essentially a collection of EC2 instances or ECS containers that AWS Batch can scale based on job requirements.
24+
25+
26+
**Checks the status of the compute Environment**
27+
28+
This operation retrieves the current status of the compute environment to ensure it is active and ready to accept jobs.
29+
30+
**Sets up a job queue and job definition**
31+
32+
This operation involves creating a job queue that will manage the submission of jobs and a job definition that specifies how the jobs should be executed.
33+
34+
**Registers a Job Definition**
35+
36+
This operation registers a new job definition with AWS Batch, making it available for job submissions.
37+
38+
**Submits a Batch Job**
39+
40+
This operation submits a job to the AWS Batch job queue for execution.
41+
42+
**Describes a Job**
43+
This operation retrieves detailed information about a specific job, including its status and execution details.
44+
45+
**Deregisters the Job Definition**
46+
his operation removes a job definition from AWS Batch, making it unavailable for future job submissions.
47+
48+
**Describes the Job Queue**
49+
50+
This operation retrieves information about a specific job queue, including its status and associated compute environments.
51+
52+
**Disables and deletes the Job Queue**
53+
This operation disables a job queue to stop it from accepting new jobs and then deletes it from AWS Batch.
54+
55+
**Disables and deletes the Compute Environment**
56+
This operation disables a compute environment to prevent it from executing new jobs and then deletes it from AWS Batch.
57+
58+
59+
### Program execution
60+
The following shows the output of the AWS Batch program in the console.
61+
62+
```
63+
AWS Batch is a fully managed batch processing service that dynamically provisions the required compute
64+
resources for batch computing workloads. The Java V2 `BatchAsyncClient` allows
65+
developers to automate the submission, monitoring, and management of batch jobs.
66+
67+
This scenario provides an example of setting up a compute environment, job queue and job definition,
68+
and then submitting a job.
69+
70+
Let's get started...
71+
72+
You have two choices:
73+
74+
1 - Run the entire program.
75+
2 - Delete an existing Compute Environment (created from a previous execution of
76+
this program that did not complete).
77+
78+
1
79+
Continuing with the program...
80+
81+
--------------------------------------------------------------------------------
82+
83+
Enter 'c' followed by <ENTER> to continue:
84+
c
85+
Continuing with the program...
86+
87+
Use AWS CloudFormation to create two IAM roles that are required for this scenario.
88+
Stack creation requested, ARN is arn:aws:cloudformation:us-east-1:814548047983:stack/BatchStack4/a3f75c50-54d1-11ef-b797-0e1c1efd9fe3
89+
Stack created successfully
90+
Stack creation requested, ARN is arn:aws:cloudformation:us-east-1:814548047983:stack/EcsStack/c8f19bb0-54d1-11ef-8454-0eebf7f4997f
91+
Stack created successfully
92+
The IAM role needed to interact wit AWS Batch is arn:aws:iam::814548047983:role/BatchStack4-RoleBatch15CD9C03-KWhgI3rvSIbY
93+
The second IAM role needed to interact wit AWS ECR is arn:aws:iam::814548047983:role/EcsStack-RoleEcsB0CD5AAE-RaUPyHZuoa1L
94+
95+
Enter 'c' followed by <ENTER> to continue:
96+
c
97+
Continuing with the program...
98+
99+
--------------------------------------------------------------------------------
100+
1. Create a Batch compute environment
101+
A compute environment is a resource where you can run your batch jobs.
102+
After creating a compute environment, you can define job queues and job definitions to submit jobs for
103+
execution.
104+
105+
The benefit of creating a compute environment is it allows you to easily configure and manage the compute
106+
resources that will be used to run your Batch jobs. By separating the compute environment from the job definitions,
107+
you can easily scale your compute resources up or down as needed, without having to modify your job definitions.
108+
This makes it easier to manage your Batch workloads and ensures that your jobs have the necessary
109+
compute resources to run efficiently.
110+
111+
112+
Enter 'c' followed by <ENTER> to continue:
113+
c
114+
Continuing with the program...
115+
116+
Compute environment created successfully.
117+
Compute Environment ARN: arn:aws:batch:us-east-1:814548047983:compute-environment/my-compute-environment
118+
119+
Enter 'c' followed by <ENTER> to continue:
120+
c
121+
Continuing with the program...
122+
123+
--------------------------------------------------------------------------------
124+
--------------------------------------------------------------------------------
125+
2. Check the status of the my-compute-environment Compute Environment.
126+
127+
Enter 'c' followed by <ENTER> to continue:
128+
c
129+
Continuing with the program...
130+
131+
Compute environment status retrieved successfully.
132+
Compute Environment Status: VALID
133+
134+
Enter 'c' followed by <ENTER> to continue:
135+
c
136+
Continuing with the program...
137+
138+
--------------------------------------------------------------------------------
139+
--------------------------------------------------------------------------------
140+
3. Create a job queue
141+
A job queue is an essential component that helps manage the execution of your batch jobs.
142+
It acts as a buffer, where jobs are placed and then scheduled for execution based on their
143+
priority and the available resources in the compute environment.
144+
145+
146+
Enter 'c' followed by <ENTER> to continue:
147+
c
148+
Continuing with the program...
149+
150+
Job queue created successfully.
151+
Job Queue ARN: arn:aws:batch:us-east-1:814548047983:job-queue/my-job-queue
152+
153+
Enter 'c' followed by <ENTER> to continue:
154+
c
155+
Continuing with the program...
156+
157+
--------------------------------------------------------------------------------
158+
4. Register a Job Definition.
159+
Registering a job in AWS Batch using the Fargate launch type ensures that all
160+
necessary parameters, such as the execution role, command to run, and so on
161+
are specified and reused across multiple job submissions.
162+
163+
The job definition pulls a Docker image from Amazon ECR and executes the Docker image.
164+
165+
166+
Enter 'c' followed by <ENTER> to continue:
167+
c
168+
Continuing with the program...
169+
170+
Job ARN: arn:aws:batch:us-east-1:814548047983:job-definition/my-job-definition:63
171+
--------------------------------------------------------------------------------
172+
--------------------------------------------------------------------------------
173+
5. Submit an AWS Batch job from a job definition.
174+
175+
Enter 'c' followed by <ENTER> to continue:
176+
c
177+
Continuing with the program...
178+
179+
Job submitted successfully. Job ID: 5a7af03d-2659-4e96-a714-94beaacce600
180+
The job id is 5a7af03d-2659-4e96-a714-94beaacce600
181+
182+
Enter 'c' followed by <ENTER> to continue:
183+
c
184+
Continuing with the program...
185+
186+
--------------------------------------------------------------------------------
187+
--------------------------------------------------------------------------------
188+
6. Get a list of jobs applicable to the job queue.
189+
190+
Enter 'c' followed by <ENTER> to continue:
191+
c
192+
Continuing with the program...
193+
194+
Job ID: e3a2b1de-01b6-4330-8a2e-f1f921a87acb, Job Name: my-job-definition, Job Status: SUCCEEDED
195+
Job ID: e7618984-49a0-44b8-85e3-e331e0cdca9a, Job Name: my-job-definition, Job Status: SUCCEEDED
196+
Job ID: b3c19bb0-65db-4097-8871-c95544a4efdb, Job Name: my-job-definition, Job Status: SUCCEEDED
197+
Job ID: 611b04a3-6c1e-415d-a733-83798c8b9d40, Job Name: my-job-definition, Job Status: SUCCEEDED
198+
Job ID: c81941d3-b3ba-4b2a-8bf2-470ff8f467aa, Job Name: my-job-definition, Job Status: SUCCEEDED
199+
Job ID: 353e105d-ca38-43cc-b4f8-52bd75418b5b, Job Name: my-job-definition, Job Status: SUCCEEDED
200+
Job ID: 77571838-dd64-454f-8b34-73fcb41ffa7c, Job Name: my-job-definition, Job Status: SUCCEEDED
201+
Job ID: 2b80159f-46d5-4d8c-ac73-6a94f19a7c74, Job Name: my-job-definition, Job Status: SUCCEEDED
202+
Job ID: fad2a2e6-a66a-4b93-ab7b-e81b833d2f6f, Job Name: my-job-definition, Job Status: SUCCEEDED
203+
Job ID: 358747fe-2c50-4d85-a965-dccd221791b7, Job Name: my-job-definition, Job Status: SUCCEEDED
204+
Job ID: 6eb60b65-5039-4da4-ae74-c5fa1d2ac633, Job Name: my-job-definition, Job Status: SUCCEEDED
205+
Job ID: 87e8798f-1104-4d8b-b9dc-fee65413bc64, Job Name: my-job-definition, Job Status: SUCCEEDED
206+
Job ID: c834a6dc-133d-47ef-80f8-f1b3b0f35408, Job Name: my-job-definition, Job Status: SUCCEEDED
207+
Job ID: 45ed52c7-4caf-462f-b713-378892b7ec77, Job Name: my-job-definition, Job Status: SUCCEEDED
208+
Job ID: 5983149a-a735-4b17-8fc3-addc7f7dee1f, Job Name: my-job-definition, Job Status: SUCCEEDED
209+
Job ID: 480c1331-af47-4485-9162-c60c241873e7, Job Name: my-job-definition, Job Status: SUCCEEDED
210+
Job ID: bb04c5b1-0913-408e-b09b-f6dbdd731d12, Job Name: my-job-definition, Job Status: SUCCEEDED
211+
Job ID: b41d72d8-f241-4335-88cc-0adf531670e8, Job Name: my-job-definition, Job Status: SUCCEEDED
212+
Job ID: 4782196d-1749-483c-b367-86281cbaf310, Job Name: my-job-definition, Job Status: SUCCEEDED
213+
Job ID: 10d617d7-b769-476e-a1be-16a68f11ee83, Job Name: my-job-definition, Job Status: SUCCEEDED
214+
Job ID: dd9b05d0-755c-4f9b-a4e4-d92bbc85b415, Job Name: my-job-definition, Job Status: SUCCEEDED
215+
Job ID: a67cd644-8d9f-4847-8192-78e9e018e020, Job Name: my-job-definition, Job Status: SUCCEEDED
216+
Job ID: aea93597-cbb3-447c-8174-c83307847b58, Job Name: my-job-definition, Job Status: SUCCEEDED
217+
Job ID: 0f4c6dce-0498-4c7d-85a0-31517634bd7f, Job Name: my-job-definition, Job Status: SUCCEEDED
218+
Job ID: 7173bf10-4c58-4d05-8028-620d71a89ff8, Job Name: my-job-definition, Job Status: SUCCEEDED
219+
Job ID: 40354da2-7f7d-42df-9e84-888b1e4e5007, Job Name: my-job-definition, Job Status: SUCCEEDED
220+
221+
Enter 'c' followed by <ENTER> to continue:
222+
c
223+
Continuing with the program...
224+
225+
--------------------------------------------------------------------------------
226+
--------------------------------------------------------------------------------
227+
7. Check the status of job 5a7af03d-2659-4e96-a714-94beaacce600
228+
229+
Enter 'c' followed by <ENTER> to continue:
230+
c
231+
Continuing with the program...
232+
233+
Job status retrieved successfully. Status: STARTING
234+
Job Status: STARTING
235+
236+
Enter 'c' followed by <ENTER> to continue:
237+
c
238+
Continuing with the program...
239+
240+
--------------------------------------------------------------------------------
241+
8. Delete Batch resources
242+
When deleting an AWS Batch compute environment, it does not happen instantaneously.
243+
There is typically a delay, similar to some other AWS resources.
244+
AWS Batch starts the deletion process.
245+
246+
Would you like to delete the AWS Batch resources such as the compute environment? (y/n)
247+
y
248+
You selected to delete the AWS ECR resources.
249+
First, we will deregister the Job Definition.
250+
251+
Enter 'c' followed by <ENTER> to continue:
252+
c
253+
Continuing with the program...
254+
255+
arn:aws:batch:us-east-1:814548047983:job-definition/my-job-definition:63 was successfully deregistered
256+
Second, we will disable and then delete the Job Queue.
257+
258+
Enter 'c' followed by <ENTER> to continue:
259+
c
260+
Continuing with the program...
261+
262+
Job queue update initiated: UpdateJobQueueResponse(JobQueueName=my-job-queue, JobQueueArn=arn:aws:batch:us-east-1:814548047983:job-queue/my-job-queue)
263+
Job queue is now disabled.
264+
265+
Enter 'c' followed by <ENTER> to continue:
266+
c
267+
Continuing with the program...
268+
269+
Lets wait 2 mins for the job queue to be deleted
270+
02:00Job queue deleted: DeleteJobQueueResponse()
271+
00:00Countdown complete!
272+
273+
Enter 'c' followed by <ENTER> to continue:
274+
c
275+
Continuing with the program...
276+
277+
Third, we will delete the Compute Environment.
278+
279+
Enter 'c' followed by <ENTER> to continue:
280+
c
281+
Continuing with the program...
282+
283+
Compute environment disabled: my-compute-environment
284+
Compute environment status retrieved successfully.
285+
Current State: UPDATING
286+
Lets wait 1 min for the compute environment to be deleted
287+
00:00Countdown complete!
288+
Compute environment was successfully deleted
289+
290+
Enter 'c' followed by <ENTER> to continue:
291+
c
292+
Continuing with the program...
293+
294+
Delete stack requested ....
295+
Stack deleted successfully.
296+
Delete stack requested ....
297+
Stack deleted successfully.
298+
--------------------------------------------------------------------------------
299+
This concludes the AWS Batch SDK scenario
300+
--------------------------------------------------------------------------------
301+
302+
```
303+
304+
## SOS Tags
305+
306+
The following table describes the metadata used in this Basics Scenario.
307+
308+
309+
| action | metadata file | metadata key |
310+
|------------------------------|------------------------------|---------------------------------------- |
311+
| `describeJobs` | batch_metadata.yaml | batch_DescribeJobs |
312+
| `updateComputeEnvironment` | batch_metadata.yaml | batch_UpdateComputeEnvironment |
313+
| `describeJobQueues` | batch_metadata.yaml | batch_DescribeJobQueues |
314+
| `DeleteJobQueue` | batch_metadata.yaml | batch_DeleteJobQueue |
315+
| `updateJobQueue` | batch_metadata.yaml | batch_UpdateJobQueue |
316+
| `deregisterJobDefinition` | batch_metadata.yaml | batch_DeregisterJobDefinition |
317+
| `registerJobDefinition` | batch_metadata.yaml | batch_RegisterJobDefinition |
318+
| `listJobsPaginator` | batch_metadata.yaml | batch_ListJobsPaginator |
319+
| `createJobQueue` | batch_metadata.yaml | batch_CreateJobQueue |
320+
| `DescribeComputeEnvironments`| batch_metadata.yaml | batch_DescribeComputeEnvironments |
321+
| `deleteComputeEnvironment` | batch_metadata.yaml | batch_DeleteComputeEnvironment |
322+
| `CreateComputeEnvironment` | batch_metadata.yaml | batch_CreateComputeEnvironment |
323+
| `scenario | batch_metadata.yaml | batch_Scenario |
324+

0 commit comments

Comments
 (0)