[PYTHON] When I tried to make a VPC with AWS CDK but couldn't make it

I tried to switch from CloudFormation to AWS CDK and the build failed well today, so make a note of the solution.

Thing you want to do

I just wanted to build an AWS sample ...! !! https://github.com/aws-samples/aws-cdk-examples/tree/master/python/ecs/fargate-load-balanced-service

Ruthless CREATE_FAILED

Unlike CloudFormation, the abstraction is intense, so you can create a VPC in one line. Instead, I don't know the contents at all.

Amazing magic code that VPC can do
vpc = ec2.Vpc(
  self, "MyVpc",
  max_azs=2
)
CREATE_FAILED ruthlessly shattering illusions
$ 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)
What he wanted to tell me
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.

Solution

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"
  ]

end

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

When I tried to make a VPC with AWS CDK but couldn't make it
I tried to make a url shortening service serverless with AWS CDK
A memorandum when I tried to get it automatically with selenium
I tried to make a calculator with Tkinter so I will write it
When I tried to change the root password with ansible, I couldn't access it.
When I tried to create a virtual environment with Python, it didn't work
[5th] I tried to make a certain authenticator-like tool with python
[2nd] I tried to make a certain authenticator-like tool with python
[3rd] I tried to make a certain authenticator-like tool with python
When I tried to create a project using Python on Docker with PyCharm, it didn't work, but it worked with Docker Compose.
I tried to make a periodical process with Selenium and Python
I tried to make a 2channel post notification application with Python
I tried to make a todo application using bottle with python
[4th] I tried to make a certain authenticator-like tool with python
I tried to make a Web API
[1st] I tried to make a certain authenticator-like tool with python
I tried to make a strange quote for Jojo with LSTM
I tried to make a mechanism of exclusive control with Go
Python: I tried to make a flat / flat_map just right with a generator
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
[AWS] [GCP] I tried to make cloud services easy to use with Python
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
[Zaif] I tried to make it easy to trade virtual currencies with Python
I want to make a game with Python
I tried to make a ○ ✕ game using TensorFlow
I tried AWS CDK!
[Python] When I tried to make a decompression tool with a zip file I just knew, I was addicted to sys.exit ()
I tried to make a periodical process with CentOS7, Selenium, Python and Chrome
I tried to make a simple mail sending application with tkinter of Python
I tried to use Java with Termux using Termux Arch but it didn't work
[Patent analysis] I tried to make a patent map with Python without spending money
I tried to make a castle search API with Elasticsearch + Sudachi + Go + echo
When I connect to a remote Jupyter Server with VScode, it's remote but local
When I tried to connect with SSH, I got a warning about free space.
Load a photo and make a handwritten sketch. With zoom function. Tried to make it.
I tried my best to make an optimization function, but it didn't work.
I tried to make a simple image recognition API with Fast API and Tensorflow
Make it easy to specify the time of AWS CloudWatch Events with CDK.
I tried to make a "fucking big literary converter"
I tried to create a table only with Django
I tried to automatically generate a password with Python3
I tried to make an OCR application with PySimpleGUI
[Introduction to AWS] I tried playing with voice-text conversion ♪
In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
I tried to make a real-time sound source separation mock with Python machine learning
I tried to make the phone ring when it was posted at the IoT post
I tried to make a memo app that can be pomodoro, but a reflection record
A Python beginner made a chat bot, so I tried to summarize how to make it.
I tried to make creative art with AI! I programmed a novelty! (Paper: Creative Adversarial Network)
A beginner tried coloring line art with chainer. I was able to do it.
I wanted to operate google spread sheet with AWS lambda, so I tried it [Part 2]
I tried to make it on / off by setting "Create a plug-in that highlights double-byte space with Sublime Text 2".
I tried to implement a volume moving average with Quantx
I tried to make various "dummy data" with Python faker
I tried to automatically create a report with Markov chain
When I try to push with heroku, it doesn't work
I want to make a blog editor with django admin
I want to make a click macro with pyautogui (desire)
I tried to solve a combination optimization problem with Qiskit
When I try to make Apache SSL, it doesn't start.