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

error: Cannot enable service discovery if a Cloudmap Namespace has not been created in the cluster #4234

Closed
gary-cowell opened this issue Sep 25, 2019 · 4 comments
Assignees
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug.

Comments

@gary-cowell
Copy link

Error thrown: Cannot enable service discovery if a Cloudmap Namespace has not been created in the cluster

Reproduction Steps

from aws_cdk import (
    aws_iam as iam,
    aws_sqs as sqs,
    aws_sns as sns,
    aws_ec2 as ec2,
    aws_logs as logs,
    aws_elasticloadbalancingv2 as elbv2,
    aws_sns_subscriptions as subs,
    aws_servicediscovery as sd,
    aws_secretsmanager as sm,
    aws_appmesh as am,
    aws_ecs as ecs,
    aws_cloudformation as cfn,
    core
)

...

        namespace = sd.PrivateDnsNamespace(self,
            id="sdnamespace",
            vpc=vpc,
            name="testnamespace",
            description="Namespace for services"
        )        
        taskDefinition=ecs.FargateTaskDefinition(self,
            id='taskdef',
            cpu=1024,
            memory_limit_mib=2048,
            execution_role=self.exerole,
            task_role=self.taskrole,
        )
        sg=ec2.SecurityGroup.from_security_group_id(self,
            id='sg',
            security_group_id='sg-1234'
        )        
        ecscluster=ecs.Cluster.from_cluster_attributes(self,
            id='cluster',
            cluster_name='testcluster',
            security_groups=[sg],        
            vpc=vpc
        )
        fargateservice=ecs.FargateService(self,
            id='fargateservice',
            task_definition=taskDefinition,
            assign_public_ip=False,
            security_group=sg,
            cluster=ecscluster,    
            cloud_map_options=ecs.CloudMapOptions(
                name='sdservice'
            )
        )

Error Log

jsii.errors.JSIIError: Cannot enable service discovery if a Cloudmap Namespace has not been created in the cluster.

$ cdk synth
jsii.errors.JavaScriptError: 
  Error: Cannot enable service discovery if a Cloudmap Namespace has not been created in the cluster.
      at FargateService.enableCloudMap (/tmp/jsii-kernel-vk5hK3/node_modules/@aws-cdk/aws-ecs/lib/base/base-service.js:239:19)
      at new BaseService (/tmp/jsii-kernel-vk5hK3/node_modules/@aws-cdk/aws-ecs/lib/base/base-service.js:53:18)
      at new FargateService (/tmp/jsii-kernel-vk5hK3/node_modules/@aws-cdk/aws-ecs/lib/fargate/fargate-service.js:30:9)
      at obj._wrapSandboxCode (/home/user/cdk/git/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6798:49)
      at Kernel._wrapSandboxCode (/home/user/cdk/git/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7253:19)
      at Kernel._create (/home/user/cdk/git/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6798:26)
      at Kernel.create (/home/user/cdk/git/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6552:21)
      at KernelHost.processRequest (/home/user/cdk/git/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6327:28)
      at KernelHost.run (/home/user/cdk/git/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6270:14)
      at Immediate.setImmediate [as _onImmediate] (/home/user/cdk/git/cdk/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6273:37)
      at runCallback (timers.js:705:18)
      at tryOnImmediate (timers.js:676:5)
      at processImmediate (timers.js:658:5)

Environment

  • **CLI Version : 1.9 **
  • **Framework Version: 1.9 **
  • **OS : debian **
  • **Language : Python 3.7 **

Other

The perhaps curious thing is, it lets me create this:

        service=sd.Service(self,
            id="sdservice",
            namespace=namespace,
            dns_record_type=sd.DnsRecordType.A,
            dns_ttl=core.Duration.seconds(300),
            name="sdservice",
            description="sdservice",
            routing_policy=sd.RoutingPolicy.WEIGHTED,
            custom_health_check=customhc
        )

So it's letting me create a Service Discovery service, but it does not let me specify a service in cloud_map_options on the FargateService.

In any event, shouldn't the FargateService cloud_map_options (or, a different option, perhaps) take the 'service' as defined by the aws_servicediscovery.Service, instead of re-specifying the options in the FargateService?


This is 🐛 Bug Report

@gary-cowell gary-cowell added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 25, 2019
@SomayaB SomayaB added the @aws-cdk/aws-servicediscovery Related to Amazon ECS Service Discovery label Sep 25, 2019
@rix0rrr rix0rrr removed the needs-triage This issue or PR still needs to be triaged. label Sep 26, 2019
@gary-cowell
Copy link
Author

I also find the problem when using ts instead of Python:

import cdk = require('@aws-cdk/core');
import s3 = require('@aws-cdk/aws-s3');
import iam = require('@aws-cdk/aws-iam');
import ec2 = require('@aws-cdk/aws-ec2');
import ecs = require('@aws-cdk/aws-ecs');
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
import sd = require('@aws-cdk/aws-servicediscovery');

export class HelloCdkStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const myvpc = new ec2.Vpc(this, 'MyVpc', { maxAzs: 2 });

    const namespace = new sd.PrivateDnsNamespace(this, 'ns', {
        vpc: myvpc,
        name: 'testnamespace',
        description: 'namespace for services'
    });

    const role = iam.Role.fromRoleArn(this, 'myrole', 'arn:aws:iam::000000000000:role/somerole');

    const taskDefinition = new ecs.FargateTaskDefinition(this, 'taskdef', {
        cpu: 1024,
        memoryLimitMiB: 2048,
        executionRole: role,
        taskRole: role
    });

    const sg = ec2.SecurityGroup.fromSecurityGroupId(this, 'mysg', 'sg-1234');

    const ecscluster = ecs.Cluster.fromClusterAttributes(this, 'cluster', {
        clusterName: 'testcluster',
        securityGroups: [ sg ],
        vpc: myvpc
    });

    const containerimage = ecs.ContainerImage.fromRegistry( 'someimage'  );

    const mycontainer = taskDefinition.addContainer('mycontainer', {
        image: containerimage,
        essential: true
    });

    const mapoptions:ecs.CloudMapOptions = { name: 'cloudmapname' }

    const fargateservice = new ecs.FargateService(this, 'myfargateservice', {
        taskDefinition: taskDefinition,
        assignPublicIp: false,
        securityGroup: sg,
        cluster: ecscluster,
        cloudMapOptions: mapoptions
    });

  }
}

Error:

** Cannot enable service discovery if a Cloudmap Namespace has not been created in the cluster. **

Again, I can define a service in the Namespace just fine:

    const customhc:sd.HealthCheckCustomConfig =  { failureThreshold: 2 } ;

    const service = new sd.Service(this, 'myservice', {
        namespace: namespace,
        dnsRecordType: sd.DnsRecordType.A,
        dnsTtl: cdk.Duration.seconds(300),
        name: 'myservice'
    });

But I can't add this to the FargateService

@gary-cowell
Copy link
Author

This error seems to go away if a defaultCloudmapNamespace is specified in ecs.ClusterAttributes

@SomayaB SomayaB assigned piradeepk and unassigned rix0rrr Oct 15, 2019
@piradeepk
Copy link
Contributor

Related: #4677

@piradeepk piradeepk added @aws-cdk/aws-ecs Related to Amazon Elastic Container and removed @aws-cdk/aws-servicediscovery Related to Amazon ECS Service Discovery labels Nov 7, 2019
@piradeepk
Copy link
Contributor

Closing this issue as #4677 should allow you to provide a cloudMapNamespace as input. Please reopen if this does not solve your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants