Issue
I have started learning AWS CDK and have a problem with below code sample copied from CDK reference page for Python: https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_ec2.README.html#vpc. It's my first attempt to write something better than just copying tutorials and I can't find where I made a mistake. Many thanks for helping me.
Configuration:
source .env/bin/activate
pip3 install -r requirements.txt
pip3 install aws_cdk.aws_ec2
My code:
from aws_cdk import (
aws_ec2 as ec2,
core
)
class CdkStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
vpc = ec2.Vpc(self, "VPC",
cidr="10.100.0.0/16",
max_azs=3,
subnet_configuration=[{
"subnet_type": ec2.SubnetType.PUBLIC,
"name": "public1",
"cidr_mask": 24
}, {
"cidr_mask": 24,
"name": "private1",
"subnet_type": ec2.SubnetType.PRIVATE
}
]
)
Error message thrown by "cdk synth" command:
(.env) [robert@fedora1 cdk]$ cdk synth
jsii.errors.JavaScriptError:
Error: Missing required properties for @aws-cdk/aws-ec2.SubnetConfiguration: subnetType
at validateRequiredProps (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7161:15)
at Object.deserialize (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6835:21)
at Kernel._toSandbox (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8111:61)
at /home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6731:40
at Array.map (<anonymous>)
at Object.deserialize (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6731:26)
at Kernel._toSandbox (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8111:61)
at /home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6841:29
at mapValues (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7101:27)
at Kernel._wrapSandboxCode (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8205:19)
at Kernel._create (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7749:26)
at Kernel.create (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7503:21)
at KernelHost.processRequest (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7293:28)
at KernelHost.run (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7233:14)
at Immediate._onImmediate (/home/robert/Documents/local/cdk/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7236:37)
at processImmediate (internal/timers.js:439:21)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "app.py", line 9, in <module>
CdkStack(app, "cdk")
File "/home/robert/Documents/local/cdk/.env/lib64/python3.7/site-packages/jsii/_runtime.py", line 66, in __call__
inst = super().__call__(*args, **kwargs)
File "/home/robert/Documents/local/cdk/cdk/cdk_stack.py", line 22, in __init__
"subnet_type": ec2.SubnetType.PRIVATE
File "/home/robert/Documents/local/cdk/.env/lib64/python3.7/site-packages/jsii/_runtime.py", line 66, in __call__
inst = super().__call__(*args, **kwargs)
File "/home/robert/Documents/local/cdk/.env/lib64/python3.7/site-packages/aws_cdk/aws_ec2/__init__.py", line 23226, in __init__
jsii.create(Vpc, self, [scope, id, props])
File "/home/robert/Documents/local/cdk/.env/lib64/python3.7/site-packages/jsii/_kernel/__init__.py", line 223, in create
interfaces=[iface.__jsii_type__ for iface in getattr(klass, "__jsii_ifaces__", [])],
File "/home/robert/Documents/local/cdk/.env/lib64/python3.7/site-packages/jsii/_kernel/providers/process.py", line 333, in create
return self._process.send(request, CreateResponse)
File "/home/robert/Documents/local/cdk/.env/lib64/python3.7/site-packages/jsii/_kernel/providers/process.py", line 318, in send
raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Missing required properties for @aws-cdk/aws-ec2.SubnetConfiguration: subnetType
Subprocess exited with error 1
Solution
You provided a list of dictionaries, but it expects a list of SubnetConfiguration objects.
subnet_configuration (Optional[List[SubnetConfiguration]])
subnet_configuration=[
ec2.SubnetConfiguration(
cidr_mask=24,
name='public1',
subnet_type=ec2.SubnetType.PUBLIC
),
ec2.SubnetConfiguration(
cidr_mask=24,
name='private1',
subnet_type=ec2.SubnetType.PRIVATE
)
]
Answered By - Vikyol
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.