This repository contains the AWS CDK (Cloud Development Kit) infrastructure code for the eRegs project. It is designed to manage and deploy various AWS resources, including Lambda functions, API Gateways, S3 buckets, and more, with environment-aware configurations and support for ephemeral environments.
- Environment-Aware Deployments: Automatically configures resources based on the target environment (e.g.,
dev
,val
,prod
, or ephemeral environments for PR previews). - Custom Synthesizer: Uses a custom CDK synthesizer configuration stored in AWS Parameter Store.
- Integrated IAM Policies: Applies IAM permissions boundaries and paths for secure resource access.
- Ephemeral Environment Support: Supports PR-based deployments with automatic cleanup policies.
- Global Aspects System: Applies global configurations like IAM paths, permissions boundaries, and removal policies.
bin/
: Entry points for deploying specific stacks (e.g.,docker-lambdas.ts
,static-assets.ts
).lib/stacks/
: Contains stack definitions for various independent stacks like the eRegs site, the parsers, the text extractor, etc.lib/constructs/
: Reusable constructs for common patterns like WAF and database setups.lib/aspects/
: Custom CDK aspects for applying global configurations.config/
: Configuration utilities for environment and stage management.utils/
: Helper functions for tasks like fetching parameters from AWS Parameter Store.
- AWS CLI configured with appropriate credentials.
- Node.js and npm installed.
- Required AWS permissions to deploy CDK stacks.
- Install dependencies:
npm install
- Bootstrap the environment (if not already done). See the README in the bootstrap directory for details.
- Determine your stack name and environment. Set
$ENV
todev
,val
,prod
, oreph-1234
for an ephemeral deploy. Set$STACK
to the name of the stack, e.g.api
,parser-launcher
. - Calculate the stack's full name:
STACK_NAME=cms-eregs-$ENV-$STACK
- Determine your entry-point filename. See the stacks section.
- Deploy a specific stack:
Replace
npx cdk deploy $STACK_NAME \ -c environment=<environment> \ -c buildId=<optional build ID> \ --require-approval never \ --exclusively \ --app "npx ts-node bin/<entry point>.ts" \ --outputs-file <outputs filename>
<environment>
with one ofdev
,val
, orprod
. For ephemeral, set<environment>
todev
and use theeph-1234
naming scheme for the stack name.
For more in-depth examples, see the Github Actions workflows located at .github/workflows/deploy-*.yml
.
Manages the redirect API with Lambda and API Gateway. Entry-point is "zip-lambdas.ts".
Handles static assets using S3 and CloudFront, with WAF integration. Supports infrastructure-only or infrastructure-plus-content deployments, to increase deployment efficiency. Use -c deploymentType=infrastructure/content
. Entry-point is "static-assets.ts".
Creates the Text Extractor service with Lambda and SQS. SQS URL is exported. Entry-point is "docker-lambdas.ts".
Combines API and database resources, including VPC configurations and S3 storage. Includes the regsite Lambda as well as supporting Lambdas: migrate, createsu, createdb, dropdb, and the authorizer function. Entry-point is "docker-lambdas.ts".
Schedules and invokes the eCFR and FR parser Lambda functions. Entry-point is "docker-lambdas.ts".
Deploys the eCFR parser Lambda function. Entry-point is "docker-lambdas.ts".
Deploys the Federal Register (FR) parser Lambda function. Entry-point is "docker-lambdas.ts".
Deploys the so-called "maintenance API", which consists simply of a Lambda function that the production API Gateway can be quickly switched to to take down the site for maintenance or repairs. Entry-point is "zip-lambdas.ts".
DEPLOY_ENV
: Specifies the deployment environment (e.g.,dev
,val
, andprod
).PR_NUMBER
: Used for ephemeral environments to identify the PR.
Key CDK-specific parameters are stored in AWS Parameter Store, such as:
/eregulations/cdk_config
: Custom synthesizer configuration./account_vars/vpc/id
: VPC ID for resource placement.
All credentials are stored in AWS Secrets Manager. The only credentials loaded at deploy-time are for setting up the database. All others are loaded at Lambda runtime.
- Use ephemeral environments for testing PRs to avoid impacting shared resources.
- Regularly update the CDK bootstrap template using the
update_template.py
script in thebootstrap/
directory. - Follow the resource naming conventions defined in
StageConfig
for consistency.
- AWS CDK Documentation
- eRegs GitHub Actions Workflow for automating updates.