Skip to content

Files

Latest commit

 

History

History

infrastructure

Digital Asset Portfolio Tracker Infrastructure

This project contains the infrastructure as code for the Digital Asset Portfolio Tracker application. It is written with the AWS CDK in TypeScript and is used to deploy AWS Services.

Infrastructure overview

The AWS CloudFormation Stacks generated by this project's CDK include:

Project folder structure

bin/

  • Main CDK entrypoint
  • Instantiates each Stack

lib/

  • Source code for each Stack written with the CDK
  • stacks/
    • AWS CDK Stack classes that define the AWS resources of the project
  • utility/
    • CDK helper functions

cdk.json

  • Defines how the CDK should build and deploy the infrastructure

Prerequisites

See the project README

Getting started

  1. Install dependencies

    npm install
    
  2. Bootstrap the CDK in your AWS environment

    Your AWS account needs to be bootstraped only once

    npx cdk bootstrap
    

    https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html

Development

Developing with the CDK is as simple as updating source code files. Once you're happy with your code, there are a couple of commands you can run to test your code:

npx cdk synth
  • Generates an AWS CloudFormation template using your local CDK code
  • Errors are thrown for invalid configuration
npx cdk diff
  • Synthesizes your local CDK code and compares it with the deployed template

The CDK documentation will come in handy when writing new CDK code: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-construct-library.html

Deployment

Deploy your infrastructure with the cdk deploy command. Since this CDK project contains multiple stacks, we pass the --all flag to deploy all of them:

npx cdk deploy --all

Deploying the web application

The CDK will deploy an AWS CodeCommit Repository and an AWS Amplify App configured to build and deploy the web application from the main branch of the CodeCommit Repository. To push this repository to the main branch of the CodeCommit Repository, follow the steps below:

  1. Authenticate your local git repository with AWS CodeCommit

    1. Navigate to this CodeCommit Repository in the AWS Console
      • The Repository should be empty, showing the Connection steps
    2. Follow the connection steps that fit your AWS account setup
  2. Set the remote URL of your repo to the CodeCommit Clone URL that matches your authentication method from the previous step:

    git remote set-url origin <CodeCommit Clone URL>
    

    Clone URLs can be copied from the Clone URL dropdown in the top right of the AWS CodeCommit console of the repo. They are also output by the cdk deploy command.

  3. Push the source code to AWS CodeCommit and kickoff the AWS Amplify App build to deploy the web app:

    git push -u origin main
    

After the code is successfully pushed to the CodeCommit Repository main branch, the Amplify App deployment will initiate. Progress can be monitored in the AWS Amplify Console.

Once the Amplify App is deployed, it will be live at the Amplify App URL. The Amplify App URL can be found in the AWS Amplify Console and is also output by the cdk deploy command.

Cleanup

To destroy all AWS resources deployed by this CDK project, run the following command:

npx cdk destroy --all

NOTE: If you generated Git credentials for your IAM user when you cloned the AWS CodeCommit repo, be sure to delete them.