Skip to content
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-ecs] Allow associating an existing Cloud Map service to an ECS service #10057

Assignees
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@otterley
Copy link
Contributor

otterley commented Aug 29, 2020

Customers who associate App Mesh Virtual Nodes with ECS services need to be able to properly configure service discovery. This entails the following steps:

  1. Create a Cloud Map namespace
  2. Create a Cloud Map service associated with the namespace
  3. Create a Virtual Node and associate it with the service
  4. Refer to the Virtual Node name in the ECS service's Envoy proxy container (APPMESH_VIRTUAL_NODE_NAME environment variable)
  5. Ensure the ECS service's service-discovery configuration updates the Cloud Map service created in step (2).

Right now, if a customer creates an ECS service and calls enableCloudMap against it, a new Cloud Map service is created by CDK, even if the customer specifies the namespace and service names created in steps (1) and (2) above. Instead, the customer needs to refer to the existing Cloud Map service in order for everything to work properly.

Here's some example code that fails:

    const mesh = new appmesh.Mesh(this, "Mesh");
    const namespace = new sd.PrivateDnsNamespace(this, "Namespace", {
      vpc,
      name: "internal.example.com",
    });
    const cloudMapService = namespace.createService("app");

    const webAppNode = new appmesh.VirtualNode(this, "AppNode", {
      mesh,
      listener: {
        portMapping: {
          port: 80,
          protocol: appmesh.Protocol.HTTP,
        },
      },
      cloudMapService,
    });

    const webService = new ecs.Ec2Service(this, "WebService", {
      // etc.
    });
    webService.enableCloudMap({
      cloudMapNamespace: cloudMapService.namespace,
      name: cloudMapService.serviceName,
    });

This results in a template with two instances of AWS::ServiceDiscovery::Service and a failure during stack creation caused by service duplication ("Service [srv-xxxxxxx] already exists").

Proposed Solution

Need some method and/or construct property on ecs.{Ec2,Fargate}Service that allows passing in an existing Cloud Map service resource.

Current workaround:

    (webService.node.children as cdk.CfnResource[])
      .find((resource) => resource.cfnResourceType === "AWS::ECS::Service")
      ?.addOverride("Properties.ServiceRegistries", [
        {
          RegistryArn: cloudMapService.serviceArn,
        },
      ]);

This is a 🚀 Feature Request

@otterley otterley added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Aug 29, 2020
@otterley otterley changed the title [aws-ecs] Allow associating an existing Cloud Map service to an ECS service [redacted] Aug 29, 2020
@otterley otterley reopened this Aug 29, 2020
@otterley otterley changed the title [redacted] [aws-ecs] Allow associating an existing Cloud Map service to an ECS service Aug 29, 2020
@SomayaB SomayaB added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Aug 31, 2020
@rizblie
Copy link

rizblie commented Nov 23, 2020

Fixing this would also enable use of apigatewayv2 with service discovery and ECS. At present it is not possible to pass the CloudMap service created by the ECS Service to an APIGateway HttpServiceDiscoveryIntegration. More detail at [aws-apigatewayv2-integrations] #11603.

@MrArnoldPalmer MrArnoldPalmer added effort/small Small work item – less than a day of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 7, 2020
@mergify mergify bot closed this as completed in #13192 Mar 9, 2021
mergify bot pushed a commit that referenced this issue Mar 9, 2021
…h an ECS service (#13192)

This PR introduces `BaseService.associateCloudMapService()` which allows the user to associate the ECS service with a CloudMap service that they provide.

**API sample**
```ts
const cloudMapService = new cloudmap.Service(...);
const ecsService = new ecs.FargateService(...);

ecsService.associateCloudMapService({
  service: cloudMapService,
});
```

Closes #10057

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Mar 9, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

This was referenced Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment