You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(ecs): add BaseService.fromServiceArnWithCluster() for use in CodePipeline (#18530)
This adds support for importing a ECS Cluster via the Arn, and not requiring the VPC or Security Groups.
This will generate an ICluster which can be used in `Ec2Service.fromEc2ServiceAttributes()` and `FargateService.fromFargateServiceAttributes()` to get an `IBaseService` which can be used in the `EcsDeployAction` to allow for cross account/region deployments in CodePipelines.
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
#### Deploying ECS applications to existing services
768
+
769
+
CodePipeline can deploy to an existing ECS service which uses the
770
+
[ECS service ARN format that contains the Cluster name](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-account-settings.html#ecs-resource-ids).
771
+
This also works if the service is in a different account and/or region than the pipeline:
772
+
773
+
```ts
774
+
import*asecsfrom'@aws-cdk/aws-ecs';
775
+
776
+
const service =ecs.BaseService.fromServiceArnWithCluster(this, 'EcsService',
// add source and build stages to the pipeline as usual...
782
+
const deployStage =pipeline.addStage({
783
+
stageName: 'Deploy',
784
+
actions: [
785
+
newcodepipeline_actions.EcsDeployAction({
786
+
actionName: 'DeployAction',
787
+
service: service,
788
+
input: buildOutput,
789
+
}),
790
+
],
791
+
});
792
+
```
793
+
794
+
When deploying across accounts, especially in a CDK Pipelines self-mutating pipeline,
795
+
it is recommended to provide the `role` property to the `EcsDeployAction`.
796
+
The Role will need to have permissions assigned to it for ECS deployment.
797
+
See [the CodePipeline documentation](https://docs.aws.amazon.com/codepipeline/latest/userguide/how-to-custom-role.html#how-to-update-role-new-services)
798
+
for the permissions needed.
799
+
767
800
#### Deploying ECS applications stored in a separate source code repository
768
801
769
802
The idiomatic CDK way of deploying an ECS application is to have your Dockerfiles and your CDK code in the same source code repository,
0 commit comments