Skip to content

Commit

Permalink
Python:ECR basis (#7181)
Browse files Browse the repository at this point in the history
* Python ecr follow

---------

Co-authored-by: David Souther <[email protected]>
  • Loading branch information
meyertst-aws and DavidSouther authored Jan 2, 2025
1 parent a88cc76 commit db53bdc
Show file tree
Hide file tree
Showing 13 changed files with 1,373 additions and 0 deletions.
104 changes: 104 additions & 0 deletions .doc_gen/metadata/ecr_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ ecr_Hello:
- description:
snippet_tags:
- ecr.java2_hello.main
Python:
versions:
- sdk_version: 3
github: python/example_code/ecr
excerpts:
- description:
snippet_tags:
- python.example_code.ecr.Hello
services:
ecr: {listImages}
ecr_PushImageCmd:
Expand Down Expand Up @@ -67,6 +75,18 @@ ecr_SetRepositoryPolicy:
- description:
snippet_tags:
- ecr.java2.set.repo.policy.main
Python:
versions:
- sdk_version: 3
github: python/example_code/ecr
excerpts:
- description:
snippet_tags:
- python.example_code.ecr.ECRWrapper.decl
- python.example_code.ecr.ECRWrapper.SetRepositoryPolicy
- description: Example that grants an IAM role download access.
snippet_tags:
- python.example_code.ecr.grant_role_download_access
services:
ecr: {SetRepositoryPolicy}
ecr_GetRepositoryPolicy:
Expand All @@ -89,6 +109,15 @@ ecr_GetRepositoryPolicy:
- description:
snippet_tags:
- ecr.java2.get.repo.policy.main
Python:
versions:
- sdk_version: 3
github: python/example_code/ecr
excerpts:
- description:
snippet_tags:
- python.example_code.ecr.ECRWrapper.decl
- python.example_code.ecr.ECRWrapper.GetRepositoryPolicy
services:
ecr: {GetRepositoryPolicy}
ecr_GetAuthorizationToken:
Expand All @@ -111,6 +140,15 @@ ecr_GetAuthorizationToken:
- description:
snippet_tags:
- ecr.java2.get.token.main
Python:
versions:
- sdk_version: 3
github: python/example_code/ecr
excerpts:
- description:
snippet_tags:
- python.example_code.ecr.ECRWrapper.decl
- python.example_code.ecr.ECRWrapper.GetAuthorizationToken
services:
ecr: {GetAuthorizationToken}
ecr_StartLifecyclePolicyPreview:
Expand All @@ -135,6 +173,22 @@ ecr_StartLifecyclePolicyPreview:
- ecr.java2.verify.image.main
services:
ecr: {StartLifecyclePolicyPreview}
ecr_PutLifeCyclePolicy:
languages:
Python:
versions:
- sdk_version: 3
github: python/example_code/ecr
excerpts:
- description:
snippet_tags:
- python.example_code.ecr.ECRWrapper.decl
- python.example_code.ecr.ECRWrapper.PutLifeCyclePolicy
- description: Example that puts an expiration date policy.
snippet_tags:
- python.example_code.ecr.put_expiration_policy
services:
ecr: {PutLifeCyclePolicy}
ecr_DescribeImages:
languages:
Kotlin:
Expand All @@ -155,6 +209,15 @@ ecr_DescribeImages:
- description:
snippet_tags:
- ecr.java2.verify.image.main
Python:
versions:
- sdk_version: 3
github: python/example_code/ecr
excerpts:
- description:
snippet_tags:
- python.example_code.ecr.ECRWrapper.decl
- python.example_code.ecr.ECRWrapper.DescribeImages
services:
ecr: {DescribeImages}
ecr_DeleteRepository:
Expand All @@ -177,6 +240,15 @@ ecr_DeleteRepository:
- description:
snippet_tags:
- ecr.java2.delete.repo.main
Python:
versions:
- sdk_version: 3
github: python/example_code/ecr
excerpts:
- description:
snippet_tags:
- python.example_code.ecr.ECRWrapper.decl
- python.example_code.ecr.ECRWrapper.DeleteRepository
services:
ecr: {DeleteRepository}
ecr_CreateRepository:
Expand All @@ -199,6 +271,15 @@ ecr_CreateRepository:
- description:
snippet_tags:
- ecr.java2.create.repo.main
Python:
versions:
- sdk_version: 3
github: python/example_code/ecr
excerpts:
- description:
snippet_tags:
- python.example_code.ecr.ECRWrapper.decl
- python.example_code.ecr.ECRWrapper.CreateRepository
services:
ecr: {CreateRepository}
ecr_DescribeRepositories:
Expand Down Expand Up @@ -230,6 +311,15 @@ ecr_DescribeRepositories:
- description:
snippet_tags:
- ecr.rust.describe-repos
Python:
versions:
- sdk_version: 3
github: python/example_code/ecr
excerpts:
- description:
snippet_tags:
- python.example_code.ecr.ECRWrapper.decl
- python.example_code.ecr.ECRWrapper.DescribeRepositories
services:
ecr: {DescribeRepositories}
ecr_ListImages:
Expand Down Expand Up @@ -282,5 +372,19 @@ ecr_Scenario_RepositoryManagement:
- description: A wrapper class for &ECR; SDK methods.
snippet_tags:
- ecr.java2_scenario.main
Python:
versions:
- sdk_version: 3
github: python/example_code/ecr
sdkguide:
excerpts:
- description: Run an interactive scenario at a command prompt.
genai: some
snippet_tags:
- python.example_code.ecr.BasicsScenario
- description: ECRWrapper class that wraps &ECR; actions.
genai: some
snippet_tags:
- python.example_code.ecr.ECRWrapper.class
services:
ecr: {CreateRepository, DescribeRepositories, DeleteRepository, DescribeImages, StartLifecyclePolicyPreview, GetAuthorizationToken, GetRepositoryPolicy, SetRepositoryPolicy}
136 changes: 136 additions & 0 deletions python/example_code/ecr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Amazon ECR code examples for the SDK for Python

## Overview

Shows how to use the AWS SDK for Python (Boto3) to work with Amazon Elastic Container Registry (Amazon ECR).

<!--custom.overview.start-->
<!--custom.overview.end-->

_Amazon ECR is a fully managed Docker container registry that makes it easy for developers to store, manage, and deploy Docker container images._

## ⚠ Important

* 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/).
* Running the tests might result in charges to your AWS account.
* 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).
* 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).

<!--custom.important.start-->
<!--custom.important.end-->

## Code examples

### Prerequisites

For prerequisites, see the [README](../../README.md#Prerequisites) in the `python` folder.

Install the packages required by these examples by running the following in a virtual environment:

```
python -m pip install -r requirements.txt
```

<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->

### Get started

- [Hello Amazon ECR](hello/hello_ecr.py#L4) (`listImages`)


### Basics

Code examples that show you how to perform the essential operations within a service.

- [Learn the basics](ecr_getting_started.py)


### Single actions

Code excerpts that show you how to call individual service functions.

- [CreateRepository](ecr_wrapper.py#L38)
- [DeleteRepository](ecr_wrapper.py#L66)
- [DescribeImages](ecr_wrapper.py#L207)
- [DescribeRepositories](ecr_wrapper.py#L161)
- [GetAuthorizationToken](ecr_wrapper.py#L142)
- [GetRepositoryPolicy](ecr_wrapper.py#L115)
- [PutLifeCyclePolicy](ecr_wrapper.py#L183)
- [SetRepositoryPolicy](ecr_wrapper.py#L88)


<!--custom.examples.start-->
<!--custom.examples.end-->

## Run the examples

### Instructions


<!--custom.instructions.start-->
<!--custom.instructions.end-->

#### Hello Amazon ECR

This example shows you how to get started using Amazon ECR.

```
python hello/hello_ecr.py
```

#### Learn the basics

This example shows you how to do the following:

- Create an Amazon ECR repository.
- Set repository policies.
- Retrieve repository URIs.
- Get Amazon ECR authorization tokens.
- Set lifecycle policies for Amazon ECR repositories.
- Push a Docker image to an Amazon ECR repository.
- Verify the existence of an image in an Amazon ECR repository.
- List Amazon ECR repositories for your account and get details about them.
- Delete Amazon ECR repositories.

<!--custom.basic_prereqs.ecr_Scenario_RepositoryManagement.start-->
<!--custom.basic_prereqs.ecr_Scenario_RepositoryManagement.end-->

Start the example by running the following at a command prompt:

```
python ecr_getting_started.py
```


<!--custom.basics.ecr_Scenario_RepositoryManagement.start-->
<!--custom.basics.ecr_Scenario_RepositoryManagement.end-->


### Tests

⚠ Running tests might result in charges to your AWS account.


To find instructions for running these tests, see the [README](../../README.md#Tests)
in the `python` folder.



<!--custom.tests.start-->
<!--custom.tests.end-->

## Additional resources

- [Amazon ECR User Guide](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html)
- [Amazon ECR API Reference](https://docs.aws.amazon.com/AmazonECR/latest/APIReference/Welcome.html)
- [SDK for Python Amazon ECR reference](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/scheduler.html)

<!--custom.resources.start-->
<!--custom.resources.end-->

---

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
14 changes: 14 additions & 0 deletions python/example_code/ecr/docker_files/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Use the official Alpine Linux image as the base image
FROM alpine:latest

# Set the working directory to /app
WORKDIR /app

# Copy the "hello.sh" script into the container
COPY hello.sh .

# Make the "hello.sh" script executable
RUN chmod +x hello.sh

# Define the command to run the "hello.sh" script
CMD ["./hello.sh"]
2 changes: 2 additions & 0 deletions python/example_code/ecr/docker_files/hello.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "Hello There!"
Loading

0 comments on commit db53bdc

Please sign in to comment.