-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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-codepipeline-actions] support cross account/region ecs deployment #11199
Comments
Hey @stocks29 , thanks for opening the issue. Do you mind showing the code that creates Thanks, |
For sure. See below. It relies on naming conventions for the cluster and service names since, aside from security groups and the vpcId, passing service/cluster information back to the pipeline stack resulted in cross-stack errors. I was actually surprised that the same didn't happen for security groups and the vpcId. // This role is generated by the cdk bootstrap process. It's generally used for deploying cloudformation to env account/regions
// but since it already has access to the artifact bucket/key and it's in account b, we'll use it for ecs deploys as well
// the service stack will handle adding ecs permissions to this role.
const deployRoleArn = `arn:aws:iam::${env.account}:role/cdk-hnb659fds-deploy-role-${env.account}-${env.region}`;
const serviceStage = new ServiceStage(this, stageName, {
env,
ecrRepoArn: ecrRepo.repositoryArn,
ecrRepoName: ecrRepo.repositoryName,
clusterName,
serviceName,
containerName: imageName,
deployRoleArn,
hostname,
});
const stage = pipeline.addApplicationStage(serviceStage);
const securityGroups = serviceStage.securityGroupIds.value.split(',')
.map((id: string, index: number) => ec2.SecurityGroup.fromSecurityGroupId(self, `${stageName}SG${index}`, id));
const vpc = ec2.Vpc.fromVpcAttributes(this, `${stageName}Vpc`, {
vpcId: serviceStage.vpcId.value,
availabilityZones: serviceStage.availZones.value.split(',')
});
const cluster = ecs.Cluster.fromClusterAttributes(this, `${stageName}Cluster`, { clusterName, vpc, securityGroups });
const ecsService = ecs.FargateService.fromFargateServiceAttributes(this, `${stageName}EcsService`, { cluster, serviceName });
const deployRole = iam.Role.fromRoleArn(this, `${stageName}EcsDeployRole`, deployRoleArn);
const action = new EcsMultiAccountDeployAction({
actionName: `${stageName}EcsDeploy`,
service: ecsService,
input: appArtifact,
runOrder: stage.nextSequentialRunOrder(),
account: env.account,
region: env.region,
role: deployRole,
}); |
Ok. So the issue here is that you're importing your service into the same Stack the CodePipeline is in, with a name. And because of that, the CDK has no way of knowing that service is defined in a different account/region. Now, there are 2 options:
However, the problem is that option .2 does not currently work in the CDK, because the account and region of the imported Service is not filled out correctly. This needs to be corrected here. For this reason, I'm keeping this issue open as a feature request (if you'd like to contribute this functionality to the CDK @stocks29 , that would be awesome - take a look at how Bucket handles that for some inspiration). Here's our Contributing guide: https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md ). |
@skinny85 How would I get the above to work if I don't have a reference to the cross account service in the stack I am deploying? |
@ryanpagel import it using a |
Hi, multi regional ecs deployments would be very useful to us. Has there been any progress on this? |
I've created a pr for the issue #15944 |
|
…aws#16997) This is a fix for the region issue raised by aws#11199 allowing multi regional ecs deployments fixes aws#11199 supersedes aws#15944, merged master and added tests ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Add account/region params and setup permissions so an
EcsDeployAction
in a pipeline inAccount A
can deploy to a different region inAccount B
.Use Case
To keep pipeline accounts separate from environment accounts and to support multi-region deployments.
Proposed Solution
I don't have an elegant proposed solution but I was able to achieve a workaround described below.
Other
I was able to cobble together a workaround by:
EcsDeployAction
to a new module (I called itEcsMultiAccountDeploy
in examples below), adding in props foraccount
andregion
which are passed to super and removing the role code.There may be a better approach but this worked for me. The reason for using the deploy role from cdk bootstrap is because it already has access to the build artifacts. Maybe there could be a way to augment the permissions of these roles during bootstrapping.
Below are the snippets of my workaround.
Important pieces from
EcsMultiAccountDeploy
In the build stack which contains the pipeline:
In the application stack:
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: