AWS Logo
Menu
Using Q Developer and CDK to create multi-region deployments

Using Q Developer and CDK to create multi-region deployments

An example of using Amazon Q Developer to convert a CDK stack from single-region to multi-region deployment.

Cameron Tod
Amazon Employee
Published Jan 30, 2025
I love using CDK with Typescript to manage deployments to AWS. Having the power of type safety, inheritance, and intellisense (autosuggest) in VSCode provides great discoverability. And being able to take advantage of development native workflows like static analysis, linting, formatting, and CI/CD is really nice too.
As Q Developer has matured, I’ve found it an increasingly valuable resource to help me out when I am coding anything, CDK or not. One of the quickest wins for me is using Q integrated into VSCode as a combination web-search/autocomplete on steroids. Whereas before, when implementing an API, I’d search the web for the API docs, then perhaps run through a bit of trial and error to get things wired up. With Q, I feel like I can shortcut a lot of that - it can generate or autocomplete a working example, which saves me a lot of context switching. I can then concentrate on ensuring I am solving the right problem.
This kind of workflow works as well with CDK as other codebases. Often I’ve found the very thought of doing a reimplementation or something I have working well exhausting. Q Developer can shortcut a lot of the stressful changing and refactoring for me.
A practical example - making a serverless app multi-region
Perhaps I have a serverless app that works pretty well. It’s been running fine for a while, and has become a key system that my team and customers rely on. As it is critical, we have decided to move it to multi-region for a couple of reasons:
  • To improve performance for customers in different parts of the world, by locating compute, storage, and database resources in AWS regions closest to end users
  • To provide a high level of resilience, so that the applicaiton remains available in the unlikely event that users are unable to access the service running in its present region
I’ve chosen a serverless example here as Amazon has built multi-region capability into a lot of our serverless services. Apps the rely on EC2 or RDS instances can definitely be deployed in a multi-region model, but often require a little more thought about how data and access to compute is managed and orchestrated. With serverless, I can focus on how Q can help without diving too deep into the underlying implementation.
I will use the sample provided here:
I clone a copy of the code and open it in VS Code. I also have the Q Developer extension installed and have signed in with my AWS Builder ID.
  • In that repo, the core stack is called SecondScreenSignOnStack. I open up cdk/lib/secondScreenSignOnStack.ts which is the source code file for that stack.
  • Then, I open the chat panel in VS Code and click the “+” to start a new session. Q is aware of the code in my workspace. So I just ask it to convert my code to multi-region:
Could you please convert this CDK stack to multi-region?
Q responds with some code, and an explanation of the changes and why they are being made. The code provided sets up some metadata, adding stack properties to specify multi-region deployments:
That’s handy, but it hasn’t provided me with code to change Dynamo. So, I just ask it to!
could you show the specific code to change dynamodb to multiregion
Even though I don‘t have the file open, Q Developer realizes that the DynamoDBTable class is imported from another file in my project, and so gives me the code I need to update that:
There’s a list of other changes it suggests too - like enabling global secondary indexes, making regions configurable, and how to update parent stacks to specify this stuff.
That is really helpful and cuts down a bunch of time I would have spent finding and reading API docs. The other nice thing is Q Developer doesn’t just provide me the code, it also describes what its done and any considerations.
There’s a line in the code that makes me think twice though:
removalPolicy: cdk.RemovalPolicy.DESTROY
That sounds like a destructive operation - I want to check to make sure I’m not going to lose any data by implementing these changes. To start my research, I highlight that piece of code in my IDE, right click, and ask Q to explain. The Q extension sends a message to the chatbot:
Explain the following part of my code: removalPolicy: RemovalPolicy.DESTROY,
There’s some more detail in the answer which I’ve left out. It explains each of the configuration options, what they do and how they impact stored data, and how to implement each.
Crucially, Q Developer also provides sources for its response - in this case, the DynamoDB Developer Guide.
Q Developer is a great tool, and in my experience, provides very accurate and usable results. But like any LLM, prompts are important, and spending a bit of time refining what you are asking it reaps big rewards. I’ve found its almost entirely replaced web searching for me when I’m coding, and is much more accurate and useful.
Q Developer has really helped me accelerate my own velocity on development projects. Perhaps more importantly, its allowed me to spend less time finding documentation and reading up about it, and more time focusing on the problems I’m solving and whether the approach I’m taking is the best one. Give it a try!
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments