Contents

Amazon Q - how to customize solutions AI generates

Introduction

Amazon Q Developer is a generative artificial intelligence (AI) powered conversational assistant that can help you understand, build, extend, and operate AWS applications. You can ask questions about AWS architecture, your AWS resources, best practices, documentation, support, and more.

Context - how to customize solutions AI generates

Amazon Q context enables fine-tuning Amazon Q to generate solutions according to your specific needs.

/posts/amazon_q_context/amazon_q_context_help.png

This is how I use it.

Overall Context Structure

For the greatest flexibility, I manage contexts on three distinct levels:

  • 🌍 Global
  • 🏠 Local
  • 💼 Business

🌍 Global Context

/posts/amazon_q_context/amazon_q_global_context.png

I use the main Global Context to instruct Amazon Q on my:

✅ General guidelines,
✅ Best practices,
✅ Personal development preferences.*

Since I mainly work with Internet of Things (IoT) solutions, I called my global context IoTGlobalAmazonQ.md. As you can see below, it is not IoT-specific (at the moment).

As you can see in the screenshot above, I use the absolute path (/Users/lmtx/dev/IoTGlobalAmazonQ.md) to ensure that every project uses the same Global Context.

This is how it looks:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# General
Ensure code maintainability and extendability.
Do not hardcode configuration into source code; use a dedicated config.ini file.
Design solutions secure by default.

# Costs
Take into account the AWS costs and optimize them.
Analyze AWS infrastructure, data ingest, and data egress costs.

# CDK
When creating an AWS CDK app, use Python and a dedicated virtual environment.
Define stacks in separate files stored in the 'stacks' directory.

## Lambda
Use the latest supported version of Python and ARM for Lambda functions.
Do not embed Lambda source code into CDK Stack or Construct; put it into a separate file.
Create dedicated CloudWatch LogGroups for every Lambda with a default retention of one year and ensure that Lambda's logger uses that LogGroup.
Add a log-level environment variable to Lambdas to enable changing the log's verbosity.

# API
Enable proxy when integrating API Gateway with Lambda; add resource("{proxy+}") and capture any method.

# Security

Use OWASP Top 10 security guidelines during design and implementation.

I’m constantly fine-tuning this file; you can find the most recent version on my GitHub. Any comments and feedback are very welcome!

*) Yes, I do believe that personal development preferences are still relevant, even in the vibe coding age.

🏠 Local Context

/posts/amazon_q_context/amazon_q_local_context.png

I use the Local Context to instruct Amazon Q on project-specific implementation:

✅ AWS CLI profile,
✅ AWS default region,
✅ Particular directives.

I use dedicated AWS CLI profiles for every assignment. My customers are located all over the world (USA, Australia, Germany, etc.), so I need to instruct Q which region to use by default for a specific engagement.

Some engagements require a unique design and development approach - Local Context is where I put those instructions for Amazon Q.

As you can see in the screenshot above, I use a project-related path (LocalAmazonQ.md), so Q searches the current directory for the Local Context.

This is how it looks*:

1
Use the 'web' aws cli profile and eu-west-1 aws region by default.

*) Since I do not want to share actual customer data, this is the Local Context I use for my website project.

💼 Business Context

/posts/amazon_q_context/amazon_q_business_context.png

I use the Business Context to instruct Amazon Q on project-specific requirements:

✅ Business goal,
✅ User experience,
✅ Functional requirements.

Sample:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# ThingRex Feedback Form Widget

A JavaScript widget that creates a floating feedback form for ThingRex.com, allowing users to ask questions and suggest topics for future articles.

## Features

- Floating form in the lower right corner of the website
- Minimized by default, automatically expands after 5 seconds
- Can be minimized, restored, or expanded to full screen
- Responsive design that works on all devices
- User authentication with AWS Cognito
- Google OAuth integration

In the Business Context, I define the business goal and the application-level requirements. I prefer to describe the backend infrastructure requirements using the Local Context and keep the Business Context user- and goal-oriented.

Summary

Let’s briefly summarize my approach; I use the:

1️⃣ Global Context to define the general guidelines and best practices.
2️⃣ Local Context to define project-specific technical details.
3️⃣ Business Context to define the functional requirements and user experience.

That clear separation allows me to focus on distinct areas when defining guidelines for Amazon Q.

In this post, I focused on explaining the foundations of Amazon Q customizations. There are more advanced methods, but this framework will for sure increase the quality of Amazon Q-generated solutions.

👉 How do you instruct AI to generate solutions tailored to your needs? Please use the feedback functionality to share your experience!

Support quality content❤️ Donate💰

Sign up for news: (by subscribing you accept the privacy policy)