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

[elasticsearch] Domain should accept a vpc and vpc_subnets properties to align with other CDK constructs #10965

Closed
2 tasks
Jon-AtAWS opened this issue Oct 19, 2020 · 9 comments · Fixed by #13900
Closed
2 tasks
Assignees
Labels
@aws-cdk/aws-elasticsearch Related to Amazon Elasticsearch Service effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1

Comments

@Jon-AtAWS
Copy link

This is somewhere between bug report and feature request

  1. change the keyword parameter from subnets= to subnet=
  2. simplify subnet selection for VPC domains

Other

I know that aws_elasticsearch is experimental. I'm struggling to get it to work.

        vpc = ec2.Vpc(self, 'cdkvpc')

        sn_private = ec2.SubnetSelection(subnet_type=ec2.SubnetType.PRIVATE)
        domain = es.Domain(self, 'cdkd1', 
                            version=es.ElasticsearchVersion.V7_7,
                            domain_name='cdkd1',
                            capacity=es.CapacityConfig(data_node_instance_type='t3.small.elasticsearch',
                                                        data_nodes=2),
                            ebs=es.EbsOptions(enabled=True, volume_size=10,
                                              volume_type=ec2.EbsDeviceVolumeType.GP2),
                            vpc_options=es.VpcOptions(security_groups=[es_sec_grp],
                                                      subnets=[sn_private]),
                            enforce_https=True,
                            node_to_node_encryption=True,
                            encryption_at_rest={
                                "enabled": True
                            },
                            use_unsigned_basic_auth=True,
                            fine_grained_access_control={
                                "master_user_name": "admin",
                            },
                          )

When I cdk deploy, I get:

jsii.errors.JSIIError: Expected object reference, got {"$jsii.struct":{"fqn":"@aws-cdk/aws-ec2.SubnetSelection","data":{"availabilityZones":null,"onePerAz":null,"subnetFilters":null,"subnetGroupName":null,"subnetName":null,"subnets":null,"subnetType":{"$jsii.enum":"@aws-cdk/aws-ec2.SubnetType/PRIVATE"}}}}

First, the above method works deploying an EC2 instance:

        sn_public = ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC)
        instance = ec2.Instance(self, 'instance',
                                instance_type=ec2.InstanceType('t3.nano'),
                                vpc=vpc,
                                machine_image=amzn_linux,
                                vpc_subnets=sn_public,
                                )

It should work that way for Amazon ES.

If I use

        selection = vpc.select_subnets(
            subnet_type=ec2.SubnetType.PRIVATE
        )
        subnets = [s for s in selection.subnets]

The error message says that you must specify a single subnet. In that case, the keyword parameter should be subnet=, instead of subnets=, and should take a single object not a list.

I also considered asking on Stack Overflow. I can't get this working, can you give me any help?

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@Jon-AtAWS Jon-AtAWS added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 19, 2020
@Jon-AtAWS
Copy link
Author

By the way, sending a single subnet

                            vpc_options=es.VpcOptions(security_groups=[es_sec_grp],
                                                      subnets=sn_private),

Gives

jsii.errors.JSIIError: Expected array type, got {"$jsii.struct":{"fqn":"@aws-cdk/aws-ec2.SubnetSelection","data":{"availabilityZones":null,"onePerAz":null,"subnetFilters":null,"subnetGroupName":null,"subnetName":null,"subnets":null,"subnetType":{"$jsii.enum":"@aws-cdk/aws-ec2.SubnetType/PRIVATE"}}}}

(Expected Array type)

@SomayaB SomayaB changed the title [aws_elasticsearch] Subnet specification is not straightforward (Python) [elasticsearch] Subnet specification is not straightforward (Python) Oct 19, 2020
@SomayaB SomayaB added the language/python Related to Python bindings label Oct 19, 2020
@github-actions github-actions bot added the @aws-cdk/aws-elasticsearch Related to Amazon Elasticsearch Service label Oct 19, 2020
@iliapolo
Copy link
Contributor

iliapolo commented Oct 20, 2020

@Jon-AtAWS The problem is that the subnets property accepts an ISubnet[], and not an ISubnetSelection[].

If you want to select only private subnets, you can do:

vpc_options=es.VpcOptions(
  security_groups=[es_sec_grp],
  # take only private subnets
  subnets=vpc.private_subnets
),

The reason its different from the ec2.Instance experience is that es.Domain doesn't actually accept a VPC, only subnets, hence it accepts subnets, and not vpc_subnets.

You mention you also used:

        selection = vpc.select_subnets(
            subnet_type=ec2.SubnetType.PRIVATE
        )
        subnets = [s for s in selection.subnets]

This should actually work, are you sure you eventually passed subnets=subnets and not subnets=[subnets]?

Thanks

@iliapolo iliapolo changed the title [elasticsearch] Subnet specification is not straightforward (Python) [elasticsearch] Domain should accept a vpc and vpc_subnets properties to align with other CDK constructs Oct 20, 2020
@iliapolo iliapolo added effort/small Small work item – less than a day of effort p2 p1 and removed language/python Related to Python bindings needs-triage This issue or PR still needs to be triaged. p2 labels Oct 20, 2020
@Jon-AtAWS
Copy link
Author

Thanks @iliapolo for the response!

Your suggestion above does not work...

        vpc = ec2.Vpc(self, 'cdkvpc')

        es_sec_grp = ec2.SecurityGroup(self, 'ESSecGrpCDK', 
                                        vpc=vpc,
                                        allow_all_outbound=True,
                                        security_group_name='ESSecGrpCDK')
        es_sec_grp.add_ingress_rule(ec2.Peer.any_ipv4(), ec2.Port.tcp(80))
        es_sec_grp.add_ingress_rule(ec2.Peer.any_ipv4(), ec2.Port.tcp(443))

        domain = es.Domain(self, 'cdkd1', 
                            version=es.ElasticsearchVersion.V7_7,
                            domain_name='cdkd1',
                            capacity=es.CapacityConfig(data_node_instance_type='t3.small.elasticsearch',
                                                        data_nodes=2),
                            ebs=es.EbsOptions(enabled=True, volume_size=10,
                                              volume_type=ec2.EbsDeviceVolumeType.GP2),
                            vpc_options=es.VpcOptions(
                                security_groups=[es_sec_grp.security_group_id],
                                subnets=vpc.private_subnets,
                            ),
                            enforce_https=True,
                            node_to_node_encryption=True,
                            encryption_at_rest={
                                "enabled": True
                            },
                            use_unsigned_basic_auth=True,
                            fine_grained_access_control={
                                "master_user_name": "admin",
                            },
                          )
                          
        masterpw = domain.master_user_password

        sn_public = ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC)

        amzn_linux = ec2.MachineImage.latest_amazon_linux(
            generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
            edition=ec2.AmazonLinuxEdition.STANDARD,
            virtualization=ec2.AmazonLinuxVirt.HVM,
            storage=ec2.AmazonLinuxStorage.GENERAL_PURPOSE
            )

(.env) handler@laptop:~/code/cdk-vpc $ cdk diff
jsii.errors.JavaScriptError:
  Error: Expected object reference, got "${Token[TOKEN.129]}"
      at Object.deserialize (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6993:23)
      at Kernel._toSandbox (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8328:61)
      at /Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6845:42
      at Array.map (<anonymous>)
      at Object.deserialize (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6845:26)
      at Kernel._toSandbox (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8328:61)
      at /Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6959:29
      at mapValues (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7231:27)
      at Object.deserialize (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6955:20)
      at Kernel._wrapSandboxCode (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8422:19)
      at Kernel._create (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7934:26)
      at Kernel.create (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7678:21)
      at KernelHost.processRequest (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7458:28)
      at KernelHost.run (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7396:14)
      at Immediate._onImmediate (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7399:37)
      at processImmediate (internal/timers.js:461:21)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "app.py", line 9, in <module>
    CdkVpcStack(app, "cdk-vpc")
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_runtime.py", line 69, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/Users/handler/code/cdk-vpc/cdk_vpc/cdk_vpc_stack.py", line 29, in __init__
    domain = es.Domain(self, 'cdkd1',
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_runtime.py", line 69, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/aws_cdk/aws_elasticsearch/__init__.py", line 4478, in __init__
    jsii.create(Domain, self, [scope, id, props])
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 250, in create
    response = self.provider.create(
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 336, in create
    return self._process.send(request, CreateResponse)
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 321, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Expected object reference, got "${Token[TOKEN.129]}"
Subprocess exited with error 1

If I use the below, I get the same error (I am passing the list without adding an additional list wrapper)

        selection = vpc.select_subnets(
            subnet_type=ec2.SubnetType.PRIVATE
        )
        subnets = [s for s in selection.subnets]

        domain = es.Domain(self, 'cdkd1', 
                            version=es.ElasticsearchVersion.V7_7,
                            domain_name='cdkd1',
                            capacity=es.CapacityConfig(data_node_instance_type='t3.small.elasticsearch',
                                                        data_nodes=2),
                            ebs=es.EbsOptions(enabled=True, volume_size=10,
                                              volume_type=ec2.EbsDeviceVolumeType.GP2),
                            vpc_options=es.VpcOptions(
                                security_groups=[es_sec_grp.security_group_id],
                                subnets=subnets,
                            ),
                            enforce_https=True,
                            node_to_node_encryption=True,
                            encryption_at_rest={
                                "enabled": True
                            },
                            use_unsigned_basic_auth=True,
                            fine_grained_access_control={
                                "master_user_name": "admin",
                            },
                          )

(.env) handler@laptop:~/code/cdk-vpc $ cdk diff
jsii.errors.JavaScriptError:
  Error: Expected object reference, got "${Token[TOKEN.129]}"
      at Object.deserialize (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6993:23)
      at Kernel._toSandbox (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8328:61)
      at /Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6845:42
      at Array.map (<anonymous>)
      at Object.deserialize (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6845:26)
      at Kernel._toSandbox (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8328:61)
      at /Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6959:29
      at mapValues (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7231:27)
      at Object.deserialize (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6955:20)
      at Kernel._wrapSandboxCode (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8422:19)
      at Kernel._create (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7934:26)
      at Kernel.create (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7678:21)
      at KernelHost.processRequest (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7458:28)
      at KernelHost.run (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7396:14)
      at Immediate._onImmediate (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7399:37)
      at processImmediate (internal/timers.js:461:21)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "app.py", line 9, in <module>
    CdkVpcStack(app, "cdk-vpc")
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_runtime.py", line 69, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/Users/handler/code/cdk-vpc/cdk_vpc/cdk_vpc_stack.py", line 26, in __init__
    domain = es.Domain(self, 'cdkd1',
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_runtime.py", line 69, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/aws_cdk/aws_elasticsearch/__init__.py", line 4478, in __init__
    jsii.create(Domain, self, [scope, id, props])
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 250, in create
    response = self.provider.create(
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 336, in create
    return self._process.send(request, CreateResponse)
  File "/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 321, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Expected object reference, got "${Token[TOKEN.129]}"

@Jon-AtAWS
Copy link
Author

I also played with passing in a dict - I got that from this sample: https://github.com/aws-samples/aws-cdk-managed-elkk. I didn't get very far with that, different errors.

            vpc_options={
                "securityGroupIds": [self.elastic_security_group.security_group_id],
                "subnetIds": vpc_stack.get_vpc_private_subnet_ids,
            },

It was complaining about getting a string IIRC. printing vpc.get_vpc_private_subnet_ids gave me some [${TOKEN:foobar}].

@iliapolo
Copy link
Contributor

@Jon-AtAWS Notice you are now passing a security group id, instead of a security group.

Your original code had:

security_groups=[es_sec_grp]

But now you have:

security_groups=[es_sec_grp.security_group_id]

Sharing the code I used which synthesizes correctly:

vpc = ec2.Vpc(self, 'cdkvpc')

es_sec_grp = ec2.SecurityGroup(self, 'DomainSG', vpc=vpc)

es.Domain(self, 'cdkd1',
  version=es.ElasticsearchVersion.V7_7,
  domain_name='cdkd1',
  capacity=es.CapacityConfig(
    data_node_instance_type='t3.small.elasticsearch',
    data_nodes=2),
  ebs=es.EbsOptions(enabled=True,
                    volume_size=10,
                    volume_type=ec2.EbsDeviceVolumeType.GP2),
  vpc_options=es.VpcOptions(security_groups=[es_sec_grp],
                            subnets=vpc.private_subnets),
  enforce_https=True,
  node_to_node_encryption=True,
  encryption_at_rest={
    "enabled": True
  },
  use_unsigned_basic_auth=True,
  fine_grained_access_control=es.AdvancedSecurityOptions(master_user_name='admin'),
)

Notice I also used es.AdvancedSecurityOptions instead of a dictionary, though the dictionary should also work but not recommended.

@Jon-AtAWS
Copy link
Author

Thank you @ilapolo, that works!

As a side feature request, the error messages are pretty impenetrable. CDK should add specific error messages, with line and character of the problem.

For instance, in this case I was focused on the wrong keyword arg, since (after digging through the Python error output) I get this one reference to my code

  File "/Users/handler/code/cdk-vpc/cdk_vpc/cdk_vpc_stack.py", line 26, in __init__
    domain = es.Domain(self, 'cdkd1',

And that only points to the beginning of the call, which spans many lines.

I'm a beginner with CDK (though experienced with CFN). At the moment, everything looks like a magic incantation, and there's really no guidebook, especially for how to put the pieces together. How can I know that I need a subnet selection and not a subnet? Lots of these decisions are automated, and lots of them you just have to know or get lucky with an example (even that didn't help me this time). Without specific and detailed error messaging, I'm pretty much at sea.

@Jon-AtAWS
Copy link
Author

Jon-AtAWS commented Oct 20, 2020

I'm not sure we're on exactly the same topic, but the deploy fails with:

4:26:58 PM | CREATE_FAILED        | AWS::Elasticsearch::Domain            | cdkd1
You must specify exactly one subnet. (Service: AWSElasticsearch; Status Code: 400; Error Code:
ValidationException; Request ID: 324293f6-4e5f-4dc7-a3b4-177ceaffd65b; Proxy: null)

For reference, I am using this in the stack.py:

        domain = es.Domain(self, 'cdkd1', 
                            version=es.ElasticsearchVersion.V7_7,
                            domain_name='cdkd1',
                            capacity=es.CapacityConfig(data_node_instance_type='t3.small.elasticsearch',
                                                        data_nodes=2),
                            ebs=es.EbsOptions(enabled=True, volume_size=10,
                                              volume_type=ec2.EbsDeviceVolumeType.GP2),
                            vpc_options=es.VpcOptions(
                                security_groups=[es_sec_grp],
                                subnets=vpc.private_subnets,
                            ),
                            enforce_https=True,
                            node_to_node_encryption=True,
                            encryption_at_rest={
                                "enabled": True
                            },
                            use_unsigned_basic_auth=True,
                            fine_grained_access_control={
                                "master_user_name": "admin",
                            },
                          )
                          

And here's the full output for diff and deploy

(.env) handler@laptop:~/code/cdk-vpc $ cdk diff
Stack cdk-vpc
IAM Statement Changes
┌───┬──────────────────────┬────────┬──────────────────────┬──────────────────────┬───────────┐
│   │ Resource             │ Effect │ Action               │ Principal            │ Condition │
├───┼──────────────────────┼────────┼──────────────────────┼──────────────────────┼───────────┤
│ + │ ${AWS679f53fac002430 │ Allow  │ sts:AssumeRole       │ Service:lambda.amazo │           │
│   │ cb0da5b7982bd2287/Se │        │                      │ naws.com             │           │
│   │ rviceRole.Arn}       │        │                      │                      │           │
├───┼──────────────────────┼────────┼──────────────────────┼──────────────────────┼───────────┤
│ + │ ${cdkd1.Arn}         │ Allow  │ es:UpdateElasticsear │ AWS:${AWS679f53fac00 │           │
│   │                      │        │ chDomainConfig       │ 2430cb0da5b7982bd228 │           │
│   │                      │        │                      │ 7/ServiceRole}       │           │
└───┴──────────────────────┴────────┴──────────────────────┴──────────────────────┴───────────┘
IAM Policy Changes
┌───┬────────────────────────────────────────────┬────────────────────────────────────────────┐
│   │ Resource                                   │ Managed Policy ARN                         │
├───┼────────────────────────────────────────────┼────────────────────────────────────────────┤
│ + │ ${AWS679f53fac002430cb0da5b7982bd2287/Serv │ arn:${AWS::Partition}:iam::aws:policy/serv │
│   │ iceRole}                                   │ ice-role/AWSLambdaBasicExecutionRole       │
└───┴────────────────────────────────────────────┴────────────────────────────────────────────┘
Security Group Changes
┌───┬────────────────────────┬─────┬────────────┬─────────────────┐
│   │ Group                  │ Dir │ Protocol   │ Peer            │
├───┼────────────────────────┼─────┼────────────┼─────────────────┤
│ + │ ${ESSecGrpCDK.GroupId} │ In  │ TCP 80     │ Everyone (IPv4) │
│ + │ ${ESSecGrpCDK.GroupId} │ In  │ TCP 443    │ Everyone (IPv4) │
│ + │ ${ESSecGrpCDK.GroupId} │ Out │ Everything │ Everyone (IPv4) │
└───┴────────────────────────┴─────┴────────────┴─────────────────┘
(NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)

Parameters
[+] Parameter AssetParameters/4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956/S3Bucket AssetParameters4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956S3Bucket72B03BC9: {"Type":"String","Description":"S3 bucket for asset \"4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956\""}
[+] Parameter AssetParameters/4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956/S3VersionKey AssetParameters4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956S3VersionKey520B7554: {"Type":"String","Description":"S3 key for asset version \"4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956\""}
[+] Parameter AssetParameters/4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956/ArtifactHash AssetParameters4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956ArtifactHashD15A2D11: {"Type":"String","Description":"Artifact hash for asset \"4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956\""}

Resources
[+] AWS::EC2::SecurityGroup ESSecGrpCDK ESSecGrpCDKBCFCDFD1
[+] AWS::SecretsManager::Secret cdkd1/MasterUser cdkd1MasterUser989CDF07
[+] AWS::Elasticsearch::Domain cdkd1 cdkd16497AD82
[+] AWS::IAM::Policy cdkd1/ESAccessPolicy/CustomResourcePolicy cdkd1ESAccessPolicyCustomResourcePolicyC8527938
[+] Custom::ElasticsearchAccessPolicy cdkd1/ESAccessPolicy/Resource cdkd1ESAccessPolicy82482E8C
[+] AWS::IAM::Role AWS679f53fac002430cb0da5b7982bd2287/ServiceRole AWS679f53fac002430cb0da5b7982bd2287ServiceRoleC1EA0FF2
[+] AWS::Lambda::Function AWS679f53fac002430cb0da5b7982bd2287 AWS679f53fac002430cb0da5b7982bd22872D164C4C

(.env) handler@laptop:~/code/cdk-vpc $ cdk deploy
<aws_cdk.core.SecretValue object at 0x100c7f910>
This deployment will make potentially sensitive changes according to your current security approval level (--require-approval broadening).
Please confirm you intend to make the following modifications:

IAM Statement Changes
┌───┬──────────────────────┬────────┬──────────────────────┬──────────────────────┬───────────┐
│   │ Resource             │ Effect │ Action               │ Principal            │ Condition │
├───┼──────────────────────┼────────┼──────────────────────┼──────────────────────┼───────────┤
│ + │ ${AWS679f53fac002430 │ Allow  │ sts:AssumeRole       │ Service:lambda.amazo │           │
│   │ cb0da5b7982bd2287/Se │        │                      │ naws.com             │           │
│   │ rviceRole.Arn}       │        │                      │                      │           │
├───┼──────────────────────┼────────┼──────────────────────┼──────────────────────┼───────────┤
│ + │ ${cdkd1.Arn}         │ Allow  │ es:UpdateElasticsear │ AWS:${AWS679f53fac00 │           │
│   │                      │        │ chDomainConfig       │ 2430cb0da5b7982bd228 │           │
│   │                      │        │                      │ 7/ServiceRole}       │           │
└───┴──────────────────────┴────────┴──────────────────────┴──────────────────────┴───────────┘
IAM Policy Changes
┌───┬────────────────────────────────────────────┬────────────────────────────────────────────┐
│   │ Resource                                   │ Managed Policy ARN                         │
├───┼────────────────────────────────────────────┼────────────────────────────────────────────┤
│ + │ ${AWS679f53fac002430cb0da5b7982bd2287/Serv │ arn:${AWS::Partition}:iam::aws:policy/serv │
│   │ iceRole}                                   │ ice-role/AWSLambdaBasicExecutionRole       │
└───┴────────────────────────────────────────────┴────────────────────────────────────────────┘
Security Group Changes
┌───┬────────────────────────┬─────┬────────────┬─────────────────┐
│   │ Group                  │ Dir │ Protocol   │ Peer            │
├───┼────────────────────────┼─────┼────────────┼─────────────────┤
│ + │ ${ESSecGrpCDK.GroupId} │ In  │ TCP 80     │ Everyone (IPv4) │
│ + │ ${ESSecGrpCDK.GroupId} │ In  │ TCP 443    │ Everyone (IPv4) │
│ + │ ${ESSecGrpCDK.GroupId} │ Out │ Everything │ Everyone (IPv4) │
└───┴────────────────────────┴─────┴────────────┴─────────────────┘
(NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)

Do you wish to deploy these changes (y/n)? y
cdk-vpc: deploying...
[0%] start: Publishing 4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956:current
[100%] success: Published 4a3609ad912843e581892f37ae9d6fb0fa1648b547693aaa562b0119452b8956:current
cdk-vpc: creating CloudFormation changeset...
4:26:58 PM | CREATE_FAILED        | AWS::Elasticsearch::Domain            | cdkd16497AD82
You must specify exactly one subnet. (Service: AWSElasticsearch; Status Code: 400; Error Code:
ValidationException; Request ID: 324293f6-4e5f-4dc7-a3b4-177ceaffd65b; Proxy: null)

	new Domain (/private/var/folders/4f/2b3kckld2mn59m48yyp5h_2hjr9cf9/T/jsii-kernel-wVrK8N/node_mo PM | UPDATE_ROLLBACK_IN_P | AWS::CloudFormation::Stack            | cdk-vpc
dules/@aws-cdk/aws-elasticsearch/lib/domain.js:650:23)
	\_ /Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtim
e.js:7934:49
	\_ Kernel._wrapSandboxCode (/Users/handler/code/cdk-vpc/.env/lib/python3.8/site-packages[███████████████████▎······································] (3/9)

4:26:58 PM | CREATE_FAILED        | AWS::Elasticsearch::Domain            | cdkd1
You must specify exactly one subnet. (Service: AWSElasticsearch; Status Code: 400; Error Code:
ValidationException; Request ID: 324293f6-4e5f-4dc7-a3b4-177ceaffd65b; Proxy: null)
4:27:00 PM | UPDATE_ROLLBACK_IN_P | AWS::CloudFormation::Stack            | cdk-vpc
The following resource(s) failed to create: [AWS679f53fac002430cb0da5b7982bd2287ServiceRoleC1EA
0FF2, cdkd16497AD82].



















 ❌  cdk-vpc failed: Error: The stack named cdk-vpc failed to deploy: UPDATE_ROLLBACK_COMPLETE
    at Object.waitForStackDeploy (/usr/local/lib/node_modules/aws-cdk/lib/api/util/cloudformation.ts:307:11)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Object.deployStack (/usr/local/lib/node_modules/aws-cdk/lib/api/deploy-stack.ts:283:26)
    at CdkToolkit.deploy (/usr/local/lib/node_modules/aws-cdk/lib/cdk-toolkit.ts:180:24)
    at initCommandLine (/usr/local/lib/node_modules/aws-cdk/bin/cdk.ts:197:9)
The stack named cdk-vpc failed to deploy: UPDATE_ROLLBACK_COMPLETE

This is pretty much what started me down the path of trying to get a single subnet.

@iliapolo
Copy link
Contributor

@Jon-AtAWS

I'm a beginner with CDK (though experienced with CFN). At the moment, everything looks like a magic incantation, and there's really no guidebook, especially for how to put the pieces together. How can I know that I need a subnet selection and not a subnet? Lots of these decisions are automated, and lots of them you just have to know or get lucky with an example (even that didn't help me this time). Without specific and detailed error messaging, I'm pretty much at sea.

Appreciate this feedback. I think some of the issue you mentioned are mitigated by compiler assistance, which of course does not exist in python. We are aware of this issue and are working to both improve the documentation and incorporate more runtime checks and contextual error messages.

You can look at this issue to see what we have planned to improve the python experience. aws/jsii#1919

Ideas on specific examples that are missing are always welcome, we keep them in a separate repository: https://github.com/aws-samples/aws-cdk-examples

As far as this issue goes, we will revamp the VPC configuration API to make it more approachable and clear.

Thanks!

@iliapolo iliapolo added effort/medium Medium work item – several days of effort and removed effort/small Small work item – less than a day of effort labels Nov 22, 2020
@mergify mergify bot closed this as completed in #13900 Apr 1, 2021
mergify bot pushed a commit that referenced this issue Apr 1, 2021
This PR includes a last minute API change that standardizes the way VPC configuration is passed to the domain. It also provides sane defaults, enabling users to simply pass `vpc` in order to connect a domain to a VPC.

In addition, I added a missing integration test for VPC enabled domains.

Resolves #10965

BREAKING CHANGE: `vpcOptions` was removed. Use `vpc`, `vpcSubnets` and `securityGroups` instead.

----

*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 Apr 1, 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.

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
This PR includes a last minute API change that standardizes the way VPC configuration is passed to the domain. It also provides sane defaults, enabling users to simply pass `vpc` in order to connect a domain to a VPC.

In addition, I added a missing integration test for VPC enabled domains.

Resolves aws#10965

BREAKING CHANGE: `vpcOptions` was removed. Use `vpc`, `vpcSubnets` and `securityGroups` instead.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-elasticsearch Related to Amazon Elasticsearch Service effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants