I tried to switch from CloudFormation to AWS CDK and the build failed well today, so make a note of the solution.
I just wanted to build an AWS sample ...! !! https://github.com/aws-samples/aws-cdk-examples/tree/master/python/ecs/fargate-load-balanced-service
Unlike CloudFormation, the abstraction is intense, so you can create a VPC in one line. Instead, I don't know the contents at all.
vpc = ec2.Vpc(
self, "MyVpc",
max_azs=2
)
$ cdk deploy
~ Abbreviation ~
Do you wish to deploy these changes (y/n)? y
~ Abbreviation ~
9/36 | 7:11:35 AM | CREATE_COMPLETE | AWS::EC2::VPC | MyVpc (MyVpcF9F0CA6F)
~ Abbreviation ~
10/36 | 7:11:38 AM | CREATE_FAILED | AWS::EC2::Subnet | MyVpc/PublicSubnet1/Subnet (MyVpcPublicSubnet1SubnetF123456) Value (ap-northeast-1a) for parameter availabilityZone is invalid. Subnets can currently only be created in the following availability zones: ap-northeast-1d, ap-northeast-1c, ap-northeast-1b. (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterValue; Request ID: xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx)
Subnets can currently only be created in the following availability zones:
ap-northeast-1d, ap-northeast-1c, ap-northeast-1b.
Yes. I've been accustomed to being swayed by the Availability Zone when creating Subnets since CloudFormation. As soon as I get used to it, I want to solve it quickly, but I'm at a loss because I don't know what to do. I understand that I was angry when I tried to make ap-northeast-1a. To put it the other way around, I don't really know why I tried to make it there.
There is availability-zones specified in the file cdk.context.json, so if there is ʻap-northeast-1a`, delete it. If not specified, add the following contents.
cdk.out/cdk.context.json
"availability-zones:account=123456789999:region=ap-northeast-1": [
"ap-northeast-1b",
"ap-northeast-1c",
"ap-northeast-1d"
]
I was worried about 3 hours ... It was hard ... I still can't get along with CDK.
By the way, if you look at gitignore, it seems that cdk.context.json is ignored, but I would be grateful if any wise man who knows where to write this setting is really.
~ Addition ~ It was written that you should set it with a command, write it in cdk.json, or specify it in the source code ^ q ^
- Through the --context option to the cdk command.
- In the context key of the project's cdk.json file.
- In the context key of a ~/cdk.json file.
- In code using the construct.node.setContext method.
https://docs.aws.amazon.com/cdk/latest/guide/context.html
Recommended Posts