- Add lifecycle policy to keep only last 10 images - Export repository ARN and name for cross-stack references
64 lines
1.6 KiB
YAML
64 lines
1.6 KiB
YAML
AWSTemplateFormatVersion: "2010-09-09"
|
|
|
|
Parameters:
|
|
RepositoryName:
|
|
Type: String
|
|
Default: blog-deployment
|
|
|
|
Resources:
|
|
# ECR Repository
|
|
Repository:
|
|
Type: AWS::ECR::Repository
|
|
DeletionPolicy: Retain
|
|
Properties:
|
|
RepositoryName: !Ref RepositoryName
|
|
ImageScanningConfiguration:
|
|
ScanOnPush: true
|
|
LifecyclePolicy:
|
|
LifecyclePolicyText: |
|
|
{
|
|
"rules": [
|
|
{
|
|
"rulePriority": 1,
|
|
"description": "Keep last 10 images",
|
|
"selection": {
|
|
"tagStatus": "any",
|
|
"countType": "imageCountMoreThan",
|
|
"countNumber": 10
|
|
},
|
|
"action": {
|
|
"type": "expire"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
RepositoryPolicyText:
|
|
Version: "2012-10-17"
|
|
Statement:
|
|
- Sid: AllowLambdaPullImage
|
|
Effect: Allow
|
|
Principal:
|
|
Service: lambda.amazonaws.com
|
|
Action:
|
|
- ecr:BatchGetImage
|
|
- ecr:BatchCheckLayerAvailability
|
|
- ecr:GetDownloadUrlForLayer
|
|
|
|
Outputs:
|
|
RepositoryUri:
|
|
Description: URI of the ECR repository
|
|
Value: !GetAtt Repository.RepositoryUri
|
|
Export:
|
|
Name: BlogDeployment-RepositoryUri
|
|
|
|
RepositoryArn:
|
|
Description: ARN of the ECR repository
|
|
Value: !GetAtt Repository.Arn
|
|
Export:
|
|
Name: BlogDeployment-RepositoryArn
|
|
|
|
RepositoryName:
|
|
Description: Name of the ECR repository
|
|
Value: !Ref RepositoryName
|
|
Export:
|
|
Name: BlogDeployment-RepositoryName
|