-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws-apprunner-alpha: accessRole
prop doesn't work
#32974
Comments
Hi @garysassano , thanks for reaching out. I am able to reproduce the scenario with the given code - const apprunnerInstanceRole = new Role(this, "ApprunnerInstanceRole", {
assumedBy: new ServicePrincipal("tasks.apprunner.amazonaws.com"),
});
const apprunnerAccessRole = new Role(this, "ApprunnerAccessRole", {
assumedBy: new ServicePrincipal("build.apprunner.amazonaws.com"),
managedPolicies: [
{
managedPolicyArn: "arn:aws:iam::aws:policy/AdministratorAccess",
},
],
});
const servicenew = new apprunner.Service(this, "ApacheService", {
accessRole: apprunnerAccessRole,
instanceRole: apprunnerInstanceRole,
source: apprunner.Source.fromEcrPublic({
imageIdentifier: "public.ecr.aws/docker/library/httpd:bookworm",
imageConfiguration: {
port: 80,
},
}),
});
} Here is the output in console when deployed - Looks like the issue exists here -
if you leave it Marking it as P3 as default role creation exists but code should also take passed value into consideration. Contribution from the community are also welcome for resolution of this bug. |
Since an access role is only set when ECR is private, this seems to be the intended behavior.
The docs states the following:
Do we need to set an access role even when using ECR Public? |
@mazyu36 My initial implementation actually used an ECR private registry configured with a pull-through cache for Docker Hub. The outcome was identical. I created a minimal reproducible code block using the Apache image solely to illustrate the issue. |
To clarify, the default access role cannot be used because you need to create an ECR registry permission that enables the IAM role used by App Runner to pull images via the pull-through cache. Here's an example implementation: apprunnerInstanceRole.addToPrincipalPolicy(
new PolicyStatement({
actions: ["ecr:*"],
resources: [
`arn:aws:ecr:${this.region}:${this.account}:repository/docker-hub/*`,
],
}),
);
const registryPolicy = new CfnRegistryPolicy(this, "EcrRegistryPolicy", {
policyText: {
Version: "2012-10-17",
Statement: [
{
Sid: "AllowPullThroughCache",
Effect: "Allow",
Principal: {
AWS: apprunnerAccessRole.roleArn,
},
Action: ["ecr:*"],
Resource:
"arn:aws:ecr:${this.region}:${this.account}:repository/docker-hub/",
},
],
},
}); Unfortunately, there's no built-in method to modify the access role policy directly. Currently, you only have the option to use It would be much better to have more idiomatic and self-explanatory methods like |
I was able to fix the issue. The problem is in the really bad design of the This is how I fixed my code: const ecr = Repository.fromRepositoryArn(
this,
"DockerHubRepo",
`arn:aws:ecr:${this.region}:${this.account}:repository/docker-hub/otel/opentelemetry-collector-contrib`,
);
const otelCollectorService = new Service(this, "OtelCollectorService", {
accessRole: apprunnerAccessRole,
instanceRole: apprunnerInstanceRole,
source: Source.fromEcr({
repository: ecr,
imageConfiguration: {
port: 4318,
startCommand: `--config https://${confmapBucket.bucketName}.s3.${this.region}.amazonaws.com/collector-confmap.yaml`,
},
}),
}); So, what are the many issues a developer has to face? First and foremost, if you specify the The reason is in this code that performs what I think is a dumb check:
It doesn't actually check if your repository is an
Instead, it simply verifies whether you used
But this is not the only bad design of the Another really bad thing is that things work completely differently based on if you use If you use If you use This inconsistency forces developers to deal with both a different property name and type for the same underlying task of specifying a repository. It's a frustrating developer experience. In my opinion, the
Developers should also have the flexibility to specify an
By eliminating unnecessary complexity and providing clear feedback, the construct could offer a much better developer experience. |
To clarify, my issue stemmed from using |
Comments on closed issues and PRs are hard for our team to see. |
Describe the bug
The
accessRole
prop in theService
L2 construct doesn't work. If you try to set it, it gets ignored.Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
I expected the App Runner service to be created with the configured access role, like for this service I manually created from AWS Console:
Current Behavior
The App Runner service gets deployed without the configured access role:
Reproduction Steps
Deploy the following Stack:
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.175.1
Framework Version
No response
Node.js Version
22.12.0
OS
Ubuntu 24.04.1
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: