- A python script to get latet image version of application from ECR.
- In some case, developers want to know the latest image version of application such master branch for deploying to staging and product.
- We can provide to them a tool (slackbot, ChatOps, etc.) to call the script.
Whatβs In This Document
π Get application code
- Get latest image version of master branch from ECR with prefix
master-
and lastestpushed at
import boto3
import re
def get_latest_master_image():
""" Filter images with prefix master- and return the latest pushed one """
client = boto3.client('ecr', region_name='ap-southeast-1')
response = client.list_images(
registryId='111111111111',
repositoryName='repo/application',
maxResults=1000
)
latest = None
temp_tag = None
for image in response['imageIds']:
tag = image['imageTag']
if re.search("^master-[0-9]+", tag):
img = client.describe_images(
registryId='111111111111',
repositoryName='repo/application',
imageIds=[
{
'imageTag': tag
},
]
)
pushed_at = img['imageDetails'][0]['imagePushedAt']
if latest is None:
latest = pushed_at
else:
if latest < pushed_at:
latest = pushed_at
temp_tag = tag
return temp_tag, latest
version, pushed_at = get_latest_master_image()
print(f'app {version} pushed at {pushed_at}')
π Run test
β‘ $ python getImageVersion.py
app master-12163 pushed at 2020-12-31 10:10:53+07:00
π A practice to use this script
- Using slackbot
Mirror:
- https://github.com/vumdao/get-ecr
- https://vumdao.hashnode.dev/how-to-get-lastest-image-version-in-aws-ecr
Read More
- Pelican-resume with docker-compose and AWS + CDK
- Using Helm Install Botkube Integrate With Slack On EKS
- Ansible AWS EC2 Dynamic Inventory Plugin
- How To List All Enabled Regions Within An AWS account
- Using AWS KMS In AWS Lambda
- Create AWS Backup Plan
- Techniques For Writing Least Privilege IAM Policies
- EKS Persistent Storage With EFS Amazon Service
- Create k8s Cronjob To Schedule Delete Expired Files
- Amazon ECR - Lifecycle Policy Rules
- Connect Postgres Database Using Lambda Function
- Using SourceIp in ALB Listener Rule
- Amazon Simple Systems Manager (SSM)
- Invalidation AWS CDN Using Boto3
- Create AWS Lambda Function Triggered By S3 Notification Event
- CI/CD Of Invalidation AWS CDN Using Gitlab Pipeline
- Create CodeDeploy
- Gitlab Pipeline With AWS Codedeploy
- Create AWS-CDK image container
- Deploy Python Lambda Functions With Container Image
- Custom CloudWatch Events
Top comments (0)