Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions 13-ECS/Practice-13.1/commands.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#LOGIN USING get-login-password
aws ecr get-login-password --region us-east-1 --profile labs | docker login --username AWS --password-stdin 324320755747.dkr.ecr.us-east-1.amazonaws.com

docker tag nginx:latest 324320755747.dkr.ecr.us-east-1.amazonaws.com/ecr:latest

docker push 324320755747.dkr.ecr.us-east-1.amazonaws.com/ecr:latest

# LOGIN USING get-authorization-token
TOKEN=$(aws ecr get-authorization-token --profile labs --output text --query 'authorizationData[].authorizationToken')

curl -i -H "Authorization: Basic $TOKEN" https://324320755747.dkr.ecr.us-east-1.amazonaws.com/v2/ecr/tags/list

# Run the image
docker run --rm -it 324320755747.dkr.ecr.us-east-1.amazonaws.com/ecr:latest
63 changes: 63 additions & 0 deletions 13-ECS/Practice-13.1/ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Description: An ECR Repository

Parameters:
repositoryName:
Description: Name for the ECR Repository
Type: String

Resources:
MyRepository:
Type: AWS::ECR::Repository
Properties:
RepositoryName: !Sub ${repositoryName}
ImageScanningConfiguration:
ScanOnPush: true
RepositoryPolicyText:
Version: "2012-10-17"
Statement:
-
Sid: AllowPushPull
Effect: Allow
Principal:
AWS:
- !Sub "arn:aws:iam::${AWS::AccountId}:user/desmond.ndambi.labs"
Action:
- "ecr:GetDownloadUrlForLayer"
- "ecr:BatchGetImage"
- "ecr:BatchCheckLayerAvailability"
- "ecr:PutImage"
- "ecr:InitiateLayerUpload"
- "ecr:UploadLayerPart"
- "ecr:CompleteLayerUpload"
LifecyclePolicy:
LifecyclePolicyText: |
{
"rules": [
{
"rulePriority": 2,
"description": "Expire images after a month",
"selection": {
"tagStatus": "any",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": 30
},
"action": { "type": "expire" }
},
{
"rulePriority": 1,
"description": "Keeps only one untagged image",
"selection": {
"tagStatus": "untagged",
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": { "type": "expire" }
}
]
}

Outputs:
MyRepository:
Description: The URI of the Repository
Value: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${repositoryName}"
6 changes: 6 additions & 0 deletions 13-ECS/Practice-13.1/parameter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"ParameterKey": "repositoryName",
"ParameterValue": "ecr"
}
]
Loading