Skip to content

Commit

Permalink
fix(ecs): make URL domain-suffix dependent (#3394)
Browse files Browse the repository at this point in the history
The ECS registry URL should be suffixed with the current partition's URL
suffix, instead of a hard-coded `amazonaws.com`.

Fixes #3377
  • Loading branch information
RomainMuller authored Jul 24, 2019
1 parent 2747a76 commit c989fa4
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C",
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17"
],
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -428,7 +428,11 @@
}
]
},
".amazonaws.com/",
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Fn::GetAtt": [
"MyImageAdoptRepository6CA902F6",
Expand Down Expand Up @@ -469,4 +473,4 @@
}
}
}
}
}
11 changes: 7 additions & 4 deletions packages/@aws-cdk/aws-codebuild/test/integ.ecr.lit.expected.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"Resources": {
"MyRepoF4F48043": {
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
"Type": "AWS::ECR::Repository",
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyProjectRole9BBE5233": {
Expand Down Expand Up @@ -170,7 +169,11 @@
}
]
},
".amazonaws.com/",
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "MyRepoF4F48043"
},
Expand All @@ -195,4 +198,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@
},
"EcrRepoBB83A592": {
"Type": "AWS::ECR::Repository",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"TaskDefTaskRole1EDB4A67": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -317,8 +317,8 @@
"Status": "Enabled"
}
},
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"EcsProjectRoleE2F0E9D2": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -536,7 +536,11 @@
}
]
},
".amazonaws.com/",
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "EcrRepoBB83A592"
}
Expand Down Expand Up @@ -1071,4 +1075,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C",
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17"
],
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -299,7 +299,11 @@
}
]
},
".amazonaws.com/",
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Fn::GetAtt": [
"DockerImageAdoptRepositoryA86481BC",
Expand All @@ -325,4 +329,4 @@
}
}
}
}
}
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-ecr/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ export abstract class RepositoryBase extends Resource implements IRepository {
*/
public repositoryUriForTag(tag?: string): string {
const tagSuffix = tag ? `:${tag}` : '';
const parts = Stack.of(this).parseArn(this.repositoryArn);
return `${parts.account}.dkr.ecr.${parts.region}.amazonaws.com/${this.repositoryName}${tagSuffix}`;
const parts = this.stack.parseArn(this.repositoryArn);
return `${parts.account}.dkr.ecr.${parts.region}.${this.stack.urlSuffix}/${this.repositoryName}${tagSuffix}`;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-ecr/test/integ.basic.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@
}
]
},
".amazonaws.com/",
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "Repo02AC86CF"
}
Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-ecr/test/test.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ export = {
{ 'Fn::Select': [ 4, arnSplit ] },
'.dkr.ecr.',
{ 'Fn::Select': [ 3, arnSplit ] },
'.amazonaws.com/',
'.',
{ Ref: 'AWS::URLSuffix' },
'/',
{ Ref: 'Repo02AC86CF' }
]]});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,6 @@
"ClusterEB0386A7": {
"Type": "AWS::ECS::Cluster"
},
"FargateServiceTaskDefwebLogGroup71FAF541": {
"Type": "AWS::Logs::LogGroup",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
},
"FargateServiceLBB353E155": {
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
"Properties": {
Expand Down Expand Up @@ -561,7 +556,11 @@
}
]
},
".amazonaws.com/",
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Fn::GetAtt": [
"FargateServiceTaskDefwebAssetImageAdoptRepositoryCDAFD419",
Expand Down Expand Up @@ -659,8 +658,13 @@
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C",
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17"
],
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"FargateServiceTaskDefwebLogGroup71FAF541": {
"Type": "AWS::Logs::LogGroup",
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"FargateServiceTaskDefExecutionRole9194820E": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -771,6 +775,7 @@
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"HealthCheckGracePeriodSeconds": 60,
"LaunchType": "FARGATE",
"LoadBalancers": [
{
Expand All @@ -781,7 +786,6 @@
}
}
],
"HealthCheckGracePeriodSeconds": 60,
"NetworkConfiguration": {
"AwsvpcConfiguration": {
"AssignPublicIp": "DISABLED",
Expand Down Expand Up @@ -1041,4 +1045,4 @@
"Description": "Artifact hash for asset \"aws-ecs-integ/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\""
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@
}
]
},
".amazonaws.com/",
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Fn::GetAtt": [
"ScheduledFargateTaskScheduledTaskDefScheduledContainerAssetImageAdoptRepository49B45957",
Expand Down Expand Up @@ -437,13 +441,13 @@
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C",
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17"
],
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"ScheduledFargateTaskScheduledTaskDefScheduledContainerLogGroup4134B16C": {
"Type": "AWS::Logs::LogGroup",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"ScheduledFargateTaskScheduledTaskDefExecutionRoleD37356D5": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -801,8 +805,8 @@
"physicalResourceId": "awsfargateintegScheduledFargateTaskScheduledTaskDefB0AD4F70"
}
},
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -1123,4 +1127,4 @@
"Description": "Artifact hash for asset \"aws-fargate-integ/AWS679f53fac002430cb0da5b7982bd2287/Code\""
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -446,37 +446,37 @@
"Resource": "*"
},
{
"Action": [
"ecs:ListContainerInstances",
"ecs:SubmitContainerStateChange",
"ecs:SubmitTaskStateChange"
],
"Effect": "Allow",
"Resource": {
"Fn::GetAtt": [
"EcsCluster97242B84",
"Arn"
]
"Action": [
"ecs:ListContainerInstances",
"ecs:SubmitContainerStateChange",
"ecs:SubmitTaskStateChange"
],
"Effect": "Allow",
"Resource": {
"Fn::GetAtt": [
"EcsCluster97242B84",
"Arn"
]
}
},
{
"Action": [
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
],
"Condition": {
"ArnEquals": {
"ecs:cluster": {
"Fn::GetAtt": [
"EcsCluster97242B84",
"Arn"
]
}
}
},
{
"Action": [
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
],
"Condition": {
"ArnEquals": {
"ecs:cluster": {
"Fn::GetAtt": [
"EcsCluster97242B84",
"Arn"
]
}
}
},
"Effect": "Allow",
"Resource": "*"
}
"Effect": "Allow",
"Resource": "*"
}
],
"Version": "2012-10-17"
},
Expand Down Expand Up @@ -740,7 +740,11 @@
}
]
},
".amazonaws.com/",
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Fn::GetAtt": [
"TaskDefTheContainerAssetImageAdoptRepository997406C3",
Expand Down Expand Up @@ -832,13 +836,13 @@
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C",
"AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17"
],
"DeletionPolicy": "Delete",
"UpdateReplacePolicy": "Delete"
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"TaskDefTheContainerLogGroupD94C8EF5": {
"Type": "AWS::Logs::LogGroup",
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain"
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"TaskDefExecutionRoleB4775C97": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -1215,4 +1219,4 @@
"Description": "Artifact hash for asset \"aws-ecs-integ-ecs/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\""
}
}
}
}
Loading

0 comments on commit c989fa4

Please sign in to comment.