Skip to content

Commit db53bdc

Browse files
Python:ECR basis (#7181)
* Python ecr follow --------- Co-authored-by: David Souther <[email protected]>
1 parent a88cc76 commit db53bdc

File tree

13 files changed

+1373
-0
lines changed

13 files changed

+1373
-0
lines changed

.doc_gen/metadata/ecr_metadata.yaml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ ecr_Hello:
2323
- description:
2424
snippet_tags:
2525
- ecr.java2_hello.main
26+
Python:
27+
versions:
28+
- sdk_version: 3
29+
github: python/example_code/ecr
30+
excerpts:
31+
- description:
32+
snippet_tags:
33+
- python.example_code.ecr.Hello
2634
services:
2735
ecr: {listImages}
2836
ecr_PushImageCmd:
@@ -67,6 +75,18 @@ ecr_SetRepositoryPolicy:
6775
- description:
6876
snippet_tags:
6977
- ecr.java2.set.repo.policy.main
78+
Python:
79+
versions:
80+
- sdk_version: 3
81+
github: python/example_code/ecr
82+
excerpts:
83+
- description:
84+
snippet_tags:
85+
- python.example_code.ecr.ECRWrapper.decl
86+
- python.example_code.ecr.ECRWrapper.SetRepositoryPolicy
87+
- description: Example that grants an IAM role download access.
88+
snippet_tags:
89+
- python.example_code.ecr.grant_role_download_access
7090
services:
7191
ecr: {SetRepositoryPolicy}
7292
ecr_GetRepositoryPolicy:
@@ -89,6 +109,15 @@ ecr_GetRepositoryPolicy:
89109
- description:
90110
snippet_tags:
91111
- ecr.java2.get.repo.policy.main
112+
Python:
113+
versions:
114+
- sdk_version: 3
115+
github: python/example_code/ecr
116+
excerpts:
117+
- description:
118+
snippet_tags:
119+
- python.example_code.ecr.ECRWrapper.decl
120+
- python.example_code.ecr.ECRWrapper.GetRepositoryPolicy
92121
services:
93122
ecr: {GetRepositoryPolicy}
94123
ecr_GetAuthorizationToken:
@@ -111,6 +140,15 @@ ecr_GetAuthorizationToken:
111140
- description:
112141
snippet_tags:
113142
- ecr.java2.get.token.main
143+
Python:
144+
versions:
145+
- sdk_version: 3
146+
github: python/example_code/ecr
147+
excerpts:
148+
- description:
149+
snippet_tags:
150+
- python.example_code.ecr.ECRWrapper.decl
151+
- python.example_code.ecr.ECRWrapper.GetAuthorizationToken
114152
services:
115153
ecr: {GetAuthorizationToken}
116154
ecr_StartLifecyclePolicyPreview:
@@ -135,6 +173,22 @@ ecr_StartLifecyclePolicyPreview:
135173
- ecr.java2.verify.image.main
136174
services:
137175
ecr: {StartLifecyclePolicyPreview}
176+
ecr_PutLifeCyclePolicy:
177+
languages:
178+
Python:
179+
versions:
180+
- sdk_version: 3
181+
github: python/example_code/ecr
182+
excerpts:
183+
- description:
184+
snippet_tags:
185+
- python.example_code.ecr.ECRWrapper.decl
186+
- python.example_code.ecr.ECRWrapper.PutLifeCyclePolicy
187+
- description: Example that puts an expiration date policy.
188+
snippet_tags:
189+
- python.example_code.ecr.put_expiration_policy
190+
services:
191+
ecr: {PutLifeCyclePolicy}
138192
ecr_DescribeImages:
139193
languages:
140194
Kotlin:
@@ -155,6 +209,15 @@ ecr_DescribeImages:
155209
- description:
156210
snippet_tags:
157211
- ecr.java2.verify.image.main
212+
Python:
213+
versions:
214+
- sdk_version: 3
215+
github: python/example_code/ecr
216+
excerpts:
217+
- description:
218+
snippet_tags:
219+
- python.example_code.ecr.ECRWrapper.decl
220+
- python.example_code.ecr.ECRWrapper.DescribeImages
158221
services:
159222
ecr: {DescribeImages}
160223
ecr_DeleteRepository:
@@ -177,6 +240,15 @@ ecr_DeleteRepository:
177240
- description:
178241
snippet_tags:
179242
- ecr.java2.delete.repo.main
243+
Python:
244+
versions:
245+
- sdk_version: 3
246+
github: python/example_code/ecr
247+
excerpts:
248+
- description:
249+
snippet_tags:
250+
- python.example_code.ecr.ECRWrapper.decl
251+
- python.example_code.ecr.ECRWrapper.DeleteRepository
180252
services:
181253
ecr: {DeleteRepository}
182254
ecr_CreateRepository:
@@ -199,6 +271,15 @@ ecr_CreateRepository:
199271
- description:
200272
snippet_tags:
201273
- ecr.java2.create.repo.main
274+
Python:
275+
versions:
276+
- sdk_version: 3
277+
github: python/example_code/ecr
278+
excerpts:
279+
- description:
280+
snippet_tags:
281+
- python.example_code.ecr.ECRWrapper.decl
282+
- python.example_code.ecr.ECRWrapper.CreateRepository
202283
services:
203284
ecr: {CreateRepository}
204285
ecr_DescribeRepositories:
@@ -230,6 +311,15 @@ ecr_DescribeRepositories:
230311
- description:
231312
snippet_tags:
232313
- ecr.rust.describe-repos
314+
Python:
315+
versions:
316+
- sdk_version: 3
317+
github: python/example_code/ecr
318+
excerpts:
319+
- description:
320+
snippet_tags:
321+
- python.example_code.ecr.ECRWrapper.decl
322+
- python.example_code.ecr.ECRWrapper.DescribeRepositories
233323
services:
234324
ecr: {DescribeRepositories}
235325
ecr_ListImages:
@@ -282,5 +372,19 @@ ecr_Scenario_RepositoryManagement:
282372
- description: A wrapper class for &ECR; SDK methods.
283373
snippet_tags:
284374
- ecr.java2_scenario.main
375+
Python:
376+
versions:
377+
- sdk_version: 3
378+
github: python/example_code/ecr
379+
sdkguide:
380+
excerpts:
381+
- description: Run an interactive scenario at a command prompt.
382+
genai: some
383+
snippet_tags:
384+
- python.example_code.ecr.BasicsScenario
385+
- description: ECRWrapper class that wraps &ECR; actions.
386+
genai: some
387+
snippet_tags:
388+
- python.example_code.ecr.ECRWrapper.class
285389
services:
286390
ecr: {CreateRepository, DescribeRepositories, DeleteRepository, DescribeImages, StartLifecyclePolicyPreview, GetAuthorizationToken, GetRepositoryPolicy, SetRepositoryPolicy}

python/example_code/ecr/README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Amazon ECR code examples for the SDK for Python
2+
3+
## Overview
4+
5+
Shows how to use the AWS SDK for Python (Boto3) to work with Amazon Elastic Container Registry (Amazon ECR).
6+
7+
<!--custom.overview.start-->
8+
<!--custom.overview.end-->
9+
10+
_Amazon ECR is a fully managed Docker container registry that makes it easy for developers to store, manage, and deploy Docker container images._
11+
12+
## ⚠ Important
13+
14+
* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/).
15+
* Running the tests might result in charges to your AWS account.
16+
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
17+
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).
18+
19+
<!--custom.important.start-->
20+
<!--custom.important.end-->
21+
22+
## Code examples
23+
24+
### Prerequisites
25+
26+
For prerequisites, see the [README](../../README.md#Prerequisites) in the `python` folder.
27+
28+
Install the packages required by these examples by running the following in a virtual environment:
29+
30+
```
31+
python -m pip install -r requirements.txt
32+
```
33+
34+
<!--custom.prerequisites.start-->
35+
<!--custom.prerequisites.end-->
36+
37+
### Get started
38+
39+
- [Hello Amazon ECR](hello/hello_ecr.py#L4) (`listImages`)
40+
41+
42+
### Basics
43+
44+
Code examples that show you how to perform the essential operations within a service.
45+
46+
- [Learn the basics](ecr_getting_started.py)
47+
48+
49+
### Single actions
50+
51+
Code excerpts that show you how to call individual service functions.
52+
53+
- [CreateRepository](ecr_wrapper.py#L38)
54+
- [DeleteRepository](ecr_wrapper.py#L66)
55+
- [DescribeImages](ecr_wrapper.py#L207)
56+
- [DescribeRepositories](ecr_wrapper.py#L161)
57+
- [GetAuthorizationToken](ecr_wrapper.py#L142)
58+
- [GetRepositoryPolicy](ecr_wrapper.py#L115)
59+
- [PutLifeCyclePolicy](ecr_wrapper.py#L183)
60+
- [SetRepositoryPolicy](ecr_wrapper.py#L88)
61+
62+
63+
<!--custom.examples.start-->
64+
<!--custom.examples.end-->
65+
66+
## Run the examples
67+
68+
### Instructions
69+
70+
71+
<!--custom.instructions.start-->
72+
<!--custom.instructions.end-->
73+
74+
#### Hello Amazon ECR
75+
76+
This example shows you how to get started using Amazon ECR.
77+
78+
```
79+
python hello/hello_ecr.py
80+
```
81+
82+
#### Learn the basics
83+
84+
This example shows you how to do the following:
85+
86+
- Create an Amazon ECR repository.
87+
- Set repository policies.
88+
- Retrieve repository URIs.
89+
- Get Amazon ECR authorization tokens.
90+
- Set lifecycle policies for Amazon ECR repositories.
91+
- Push a Docker image to an Amazon ECR repository.
92+
- Verify the existence of an image in an Amazon ECR repository.
93+
- List Amazon ECR repositories for your account and get details about them.
94+
- Delete Amazon ECR repositories.
95+
96+
<!--custom.basic_prereqs.ecr_Scenario_RepositoryManagement.start-->
97+
<!--custom.basic_prereqs.ecr_Scenario_RepositoryManagement.end-->
98+
99+
Start the example by running the following at a command prompt:
100+
101+
```
102+
python ecr_getting_started.py
103+
```
104+
105+
106+
<!--custom.basics.ecr_Scenario_RepositoryManagement.start-->
107+
<!--custom.basics.ecr_Scenario_RepositoryManagement.end-->
108+
109+
110+
### Tests
111+
112+
⚠ Running tests might result in charges to your AWS account.
113+
114+
115+
To find instructions for running these tests, see the [README](../../README.md#Tests)
116+
in the `python` folder.
117+
118+
119+
120+
<!--custom.tests.start-->
121+
<!--custom.tests.end-->
122+
123+
## Additional resources
124+
125+
- [Amazon ECR User Guide](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html)
126+
- [Amazon ECR API Reference](https://docs.aws.amazon.com/AmazonECR/latest/APIReference/Welcome.html)
127+
- [SDK for Python Amazon ECR reference](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/scheduler.html)
128+
129+
<!--custom.resources.start-->
130+
<!--custom.resources.end-->
131+
132+
---
133+
134+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
135+
136+
SPDX-License-Identifier: Apache-2.0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Use the official Alpine Linux image as the base image
2+
FROM alpine:latest
3+
4+
# Set the working directory to /app
5+
WORKDIR /app
6+
7+
# Copy the "hello.sh" script into the container
8+
COPY hello.sh .
9+
10+
# Make the "hello.sh" script executable
11+
RUN chmod +x hello.sh
12+
13+
# Define the command to run the "hello.sh" script
14+
CMD ["./hello.sh"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
echo "Hello There!"

0 commit comments

Comments
 (0)