-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Apprunner: After pushing a Docker image to ECR, isn't triggered. #26640
Description
Describe the bug
Deployed AppRunner using AWS CDK.
The expected behavior is for AppRunner to automatically deploy upon each change to the container image in ECR.
Expected Behavior
After pushing a Docker image to ECR, the AppRunner deployment is triggered.
Current Behavior
However, even after pushing a Docker image to ECR, the AppRunner deployment isn't triggered.
Reproduction Steps
import * as apprunner from '@aws-cdk/aws-apprunner-alpha'
import { Cpu, Memory } from '@aws-cdk/aws-apprunner-alpha'
import * as cdk from 'aws-cdk-lib'
import * as iam from 'aws-cdk-lib/aws-iam'
import { Construct } from 'constructs'
import { EcrStack } from './ecr'
export class AppRunnerStack extends cdk.Stack {
constructor(
scope: Construct,
id: string,
ecrStack: EcrStack,
props?: cdk.StackProps,
) {
super(scope, id, props)
new apprunner.Service(this, 'SampleAppRunnerService', {
serviceName: 'sample-app',
cpu: Cpu.ONE_VCPU,
memory: Memory.TWO_GB,
autoDeploymentsEnabled: true,
source: apprunner.Source.fromEcr({
imageConfiguration: {
port: 3000,
startCommand: 'npm run start --workspace=app',
},
repository: ecrStack.repository,
tagOrDigest: 'latest',
}),
})
}
}
Possible Solution
Cause:
The access role for AppRunner’s service is automatically generated. However, it lacks permission for the ecr:DescribeImages action, preventing it from detecting image changes.
Necessary Permissions:
Actions required for ECR access:
- ecr:BatchCheckLayerAvailability
- ecr:GetDownloadUrlForLayer
- ecr:BatchGetImage
- ecr:GetAuthorizationToken
Actions that AppRunner needs for ECR access:
- ecr:GetDownloadUrlForLayer
- ecr:BatchCheckLayerAvailability
- ecr:BatchGetImage
- ecr:DescribeImages
- ecr:GetAuthorizationToken
Proposed Solution:
- Add the ecr:DescribeImages action to the access role of AppRunner's service.
- Attach the IAM policy that includes the above actions to AppRunner.
- Make the AccessRole public to allow users to access it.
Additional Information/Context
https://zenn.dev/okaharuna/articles/bed7f41498a1b6
CDK CLI Version
2.89.0
Framework Version
No response
Node.js Version
any
OS
any
Language
Typescript
Language Version
No response
Other information
No response