- AWS account and a good understanding of AWS services and billing/cost management
- AWS account OIDC role(recommended) OR IAM role credentials with necessary service permissions
- Nodejs/npm installation
- aws-cdk installation
-
Clone the repository using HTTPS to your computer.
-
Do one of the two options listed below to test our Cloudformation Template in our local before proceeding with CI/CD deployment;
- Create a
.env
file in your project's root folder and add all the environment variables in.env.example
to your.env
. - This .env will only be used for
synth
command. We will NEVER expose this to any deployment. - For sanity check, confirm that
.env
is already added to.gitignore
and it is not tracked in version control.
- In your projects's root directory;
- run
npm run rename
and enter the name of your project so the script can properly update all corresponding fields with this new name. Note that only alphanumeric characters, hyphens and underscores are allowed.(no spaces). - confirm that you see success messages in the CLI after executing the script.
- run
npm i
and wait for the dependency installation to be complete.
- Now we can verify if our local setup is ready;
- run
npm run synth
and see if you get any errors. This will do two things;- verify that your
.env
has everything defined in.env.example
. It will warn you if something is missing. - run
cdk synth
command to emit your cdk stack to CloudFormation template to see if there is any error.
- verify that your
- a succesful run should output a bunch of texts (aka cloudformation template).
- Your local project configuration is now set up. You can now create your NestedStacks in
lib/nested-stacks
and instantiate them inlib/MainStack.ts
. For convenience, there are a bunch of constructs inlib/constructs
folder for commonly used services. They are convenient wrappers and they can be modified/extended as desired based on application requirements and developer preferences.
(Optional): You can install aws-cdk globally and configure your aws cli credentials to use cdk bootstrap aws://ACCOUNT_ID/REGION
(only required once per aws account) && cdk deploy
to deploy your code without CI/CD. However, note that this may require additional configuration depending on the complexity of your project(profiles, env variables etc) and using CI/CD for deployment is the recommended approach.
- The repository has CI/CD workflow defined in
.github/workflows/main.yml
fordevelop
andmain
branches. Any push to these branches will trigger CI/CD. However, for the action to run succesfully, we need to createdevelop
andmain
environments and inject some secrets into them via Github Secrets. To do that;
- Go to your repository
settings
on Github. - Click
Environments
and create two environments calleddevelop
andmain
. This is how workflow file is set up out of the box and it will look for these environments during deployment. You can change their names however you like in themain.yml
workflow and update your environments correspondingly. If you only needmain
branch configuration for example, you don't need to createdevelop
environment. - Click
Secrets and Variables
and thenActions
- Set the following env variables as either repository secrets or environment secrets(if you are using multiple environments(dev,qa,prod etc and values change depending on the environment))
ENVIRONMENT
:develop
ormain
for the original workfile. Should be added as an environment secret
AWS_ACCESS_KEY_ID
: your aws account access key id
AWS_SECRET_ACCESS_KEY
: your aws account secret access key
- Next, add all the env variables in your local
.env
as a repository or environment variable(or a secret). Keep in mind that secrets cannot be viewed after saving them while variables can always be viewed.
Your secrets and variables should look like this;
- Remember that every time you need a new env variable, you need to add them to the following;
- to
env
field for each branch in.github/workflows/main.yml
file - to
bin/{your_app_name}.ts
file as a prop to introduce it to your main stack - to any nested stack as a prop that will inherit the env variable from the parent stack
In addition, for your local development, you will also need to update your .env
and .env.example
for consistency.
- Now, you can either directly push or make a PR to your
develop
ormain
branches(create them if you don't have them) and the deployment will execute automatically on condition that you followed all the steps carefully. Your deployment status can be tracked in theactions
tab of your github repository.
If this is your first time deploying a cdk stack to your aws account, you should run cdk bootstrap aws://ACCOUNT_ID/REGION
to create the required resources before deployment.