Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cdk): Add multi-environment deployment support #778

Open
wants to merge 22 commits into
base: v2
Choose a base branch
from

Conversation

konokenj
Copy link
Contributor

Close #720

Adds support for deploying multiple environments (dev, test, prod, etc.) within the same AWS account. It introduces a type-safe parameter management system using Zod and enables environment-specific resource naming.

Key Features

  • Type-safe parameter management: Added parameter-models.ts with Zod schemas for better developer experience and type safety
  • Multi-environment support: Implemented environment name and prefix concepts for stack and resource isolation
  • Parameter resolution flexibility: Support for parameters from cdk.json, parameter.ts, or environment variables
  • Resource naming with prefixes: Added environment prefixes to stack names and resources which have physical name
  • Environment tagging: All resources are tagged with CDKEnvironment for identification

Implementation Details

  • Added environment name and prefix parameters to all relevant constructs
  • Modified CloudFormation exports to include environment prefixes
  • Updated CodeBuild projects to pass environment variables
  • Added environment tags to resources including Secrets Manager secrets
  • Created a flexible parameter resolution system that works with multiple sources

Notes

  • Custom bot stacks and API publishing stacks are not prefixed by environment name as they are created dynamically
  • Existing users can continue using cdk.json without any changes
  • Resources can be identified by their CDKEnvironment tag
  • bin/api-publish.ts used context parameters to pass parameters. This was redundant, so it was fixed to be passed as an environment variable.
  • Since bin/bedrock-custom-bot.ts uses so many parameters, log output and stack delivery are complicated, and mistakes are likely to occur. I structured the bin script a bit, but it would be better to structure the stack props. Since this requires a snapshot test, we can improve it with another PR.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

konokenj added 21 commits March 7, 2025 19:28
- Create separate parameter models for each entry point using Zod
- Define BaseParametersSchema for common parameters across all entry points
- Implement specific parameter schemas for bedrock-chat, api-publish, and bedrock-custom-bot
- Add type-safe parameter retrieval functions for each entry point
- Simplify parameter handling in entry point files
- Ensure proper default values and validation for all parameters
Add ability to specify environment name when getting Bedrock chat parameters.
When envName is provided, parameters are fetched from bedrockChatParams map.
If envName is undefined, 'default' is used.
If 'default' is not found in the map, CDK context values are used.
For non-default environments, an error is thrown if not found in the map.
…per experience

- Use z.input for input types to allow optional parameters with defaults
- Use z.infer for output types to ensure all properties are required
- Remove unnecessary .optional() calls from properties with defaults
- Update parameter.ts to use the new input type
- Ensure getBedrockChatParameters returns fully resolved parameters

This change allows users to pass empty objects to bedrockChatParams while
maintaining strong typing for the returned parameters from get*Parameters functions.
…loyments

- Rename parameter getter functions to better reflect their purpose (get* -> resolve*)
- Add explicit App type for better type safety
- Improve handling of array parameters with proper null checks
- Add default value for publishedApiAllowedOrigins
- Add unit tests for parameter resolution functions
…support

Move envName and envPrefix to BaseParameterSchema and add functionality to retrieve
parameters from environment variables. This allows handling context parameters from
tryGetContext and environment variables using the same mechanism.

- Add getEnvVar helper function to parameter-models.ts
- Extend BedrockCustomBotParametersSchema with required parameters
- Update resolveBedrockCustomBotParameters to retrieve parameters from environment variables
- Similarly update resolveApiPublishParameters
- Modify bin/bedrock-custom-bot.ts and bin/api-publish.ts to use the new parameter handling
- Simplify debug logging and standardize to JSON format
- Update function comments to clarify that values are retrieved from environment variables
@statefb
Copy link
Contributor

statefb commented Mar 18, 2025

Related: #659 #727

@statefb
Copy link
Contributor

statefb commented Mar 19, 2025

Memo

env_name / env_prefix

  1. Primary usage:
    env_name: Used for environment identification, CDK tagging (cdk.Tags.of(app).add("CDKEnvironment", params.envName)), and as keys in parameter maps
    env_prefix: Used for resource naming (${params.envPrefix}${sepHyphen}BedrockChatStack) to prevent name conflicts

  2. Default environment handling: When env_name is "default", env_prefix becomes empty

  3. Relationship: For non-default environments, env_prefix equals env_name, but they remain separate parameters to maintain conceptual clarity

@konokenj
Copy link
Contributor Author

@statefb Thank you for your review! Fixed them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants