Last active
September 13, 2022 02:05
-
-
Save techthoughts2/136f88660f47aedde94bdf7047a81e16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AWS CDK Typescript setup on Windows | |
## Install Requirements | |
```bash | |
# install nodejs | |
winget install OpenJS.NodeJS | |
# if already installed upgrade | |
winget upgrade OpenJS.NodeJS | |
#! You will need to close and re-open your shell | |
# check versions of node and npm | |
node -v | |
npm -v | |
# Install the TypeScript compiler | |
npm install -g typescript | |
# check version and get help | |
tsc --version | |
tsc --help | |
# install useful VSCode extensions for typescript | |
code --install-extension dbaeumer.vscode-eslint | |
# install the aws cdk globally | |
npm install -g aws-cdk | |
# update the aws cdk if already installed | |
npm install -g aws-cdk | |
# check cdk version | |
cdk --version | |
# install aws cdk library - optional, will be done automatically during project scaffold | |
https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html | |
npm install aws-cdk-lib | |
# install aws cli | |
winget install Amazon.AWSCLI | |
# if already installed upgrade | |
winget upgrade Amazon.AWSCLI | |
``` | |
## Creating first project | |
```bash | |
# setup aws cli credentials as needed | |
# determine aws account number | |
aws sts get-caller-identity | |
aws sts get-caller-identity --profile profilename | |
# bootstrap the AWS account | |
cdk bootstrap aws://ACCOUNT-NUMBER/REGION | |
# create a project | |
mkdir my-project | |
cd my-project | |
cdk init app --language typescript | |
``` | |
### Project directory breakdown | |
- ```bin/cdk-workshop.ts``` - entrypoint of the CDK application. It will load the stack defined in ```lib/cdk-workshop-stack.ts```. | |
- ```lib/cdk-workshop-stack.ts``` - CDK application’s main stack is defined. Where you will spend most of your time. | |
- ```node_modules``` - maintained by npm and includes all your project’s dependencies. | |
- ```test``` | |
- ```.gitignore``` & ````.npmignore``` - tell git and npm which files to include/exclude from source control and when publishing this module to the package manager. | |
- ```cdk.json``` - tells the toolkit how to run your app. Ex. ```npx ts-node bin/cdk-workshop.ts``` | |
- ```jest.config.js``` | |
- ```package-lock.json``` - maintained by npm | |
- ```package.json``` - npm module manifest. Includes information like the name of your app, version, dependencies and build scripts like “watch” and “build” | |
- ```tsconfig.json``` - typescript configuration | |
### Working with project | |
*Note: ```cdk``` commands must be run from same directory as ```cdk.json```* | |
```bash | |
# synthesize a CFN template | |
cdk synth | |
# deploy | |
cdk deploy | |
cdk deploy --profile profilename | |
# check the difference | |
cdk diff | |
cdk diff --profile profilename | |
# hotswap deployment to avoid CFN change in dev env - not for production | |
cdk deploy --hotswap | |
cdk deploy --hotswap --profile profilename | |
# destroy stack | |
cdk destroy | |
``` | |
### Testing Constructs | |
```aws-cdk-lib/assertions``` | |
## Links | |
### CDK | |
#### CDK Terms | |
**Construct** - Constructs are the basic building blocks of AWS CDK apps. A construct represents a "cloud component" and encapsulates everything AWS Cloud Formation needs to create the component. | |
**Stack** - The unit of deployment in the AWS CDK is called a stack. All AWS resources defined within the scope of a stack, either directly or indirectly, are provisioned as a single unit. | |
**App** - An App is a container for one or more stacks: it serves as each stack's scope. | |
**Environment** - Each Stack instance in your AWS CDK app is explicitly or implicitly associated with an environment (env). An environment is the target AWS account and region into which the stack is intended to be deployed. | |
**Bootstrapping** - Deploying AWS CDK apps into an AWS environment (a combination of an AWS account and region) requires that you provision resources the AWS CDK needs to perform the deployment. These resources include an Amazon S3 bucket for storing files and IAM roles that grant permissions needed to perform deployments. The process of provisioning these initial resources is called bootstrapping. | |
#### CDK Guides & Info | |
- [What is the AWS CDK?](https://docs.aws.amazon.com/cdk/v2/guide/home.html) | |
- [Working with the AWS CDK in TypeScript](https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-typescript.html) | |
- [AWS Cloud Development Kit (CDK) – TypeScript and Python are Now Generally Available](https://aws.amazon.com/blogs/aws/aws-cloud-development-kit-cdk-typescript-and-python-are-now-generally-available/) | |
- [AWS CDK for VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/cdk-explorer.html) | |
- Videos | |
#### CDK References | |
- [AWS CDK Reference Documentation](https://docs.aws.amazon.com/cdk/api/v2/) | |
- [AWS CDK API Reference](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-construct-library.html) | |
- [Construct Hub](https://constructs.dev/) | |
- [AWS CDK Developer Guide html](https://docs.aws.amazon.com/cdk/v2/guide/work-with.html) | |
- [Concepts](https://docs.aws.amazon.com/cdk/v2/guide/core_concepts.html) | |
- [Testing constructs](https://docs.aws.amazon.com/cdk/v2/guide/testing.html) | |
- [AWS CDK Developer Guide pdf](https://docs.aws.amazon.com/cdk/v2/guide/awscdk.pdf) | |
- [AWS CDK tools](https://docs.aws.amazon.com/cdk/v2/guide/tools.html) | |
- [AWS CDK Toolkit (cdk command)](https://docs.aws.amazon.com/cdk/v2/guide/cli.html) | |
- [AWS Toolkit for Visual Studio Code](https://docs.aws.amazon.com/cdk/v2/guide/vscode.html) | |
- [AWS SAM integration](https://docs.aws.amazon.com/cdk/v2/guide/sam.html) | |
- [Best practices for developing and deploying cloud infrastructure with the AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/best-practices.html) | |
- [Increasing development speed with CDK Watch](https://aws.amazon.com/blogs/developer/increasing-development-speed-with-cdk-watch/) | |
- [AWS CDK experimental packages search](https://www.npmjs.com/search?q=%40aws-cdk) | |
- [aws-samples/aws-cdk-examples](https://github.com/aws-samples/aws-cdk-examples) | |
- [CDK Patterns](https://cdkpatterns.com/) | |
- [cdk-patterns/serverless](https://github.com/cdk-patterns/serverless) | |
- [aws-samples / aws-cdk-intro-workshop](https://github.com/aws-samples/aws-cdk-intro-workshop) | |
- [awslabs/aws-solutions-constructs](https://github.com/awslabs/aws-solutions-constructs) | |
- [CDK Pipelines: Continuous delivery for AWS CDK applications](https://aws.amazon.com/blogs/developer/cdk-pipelines-continuous-delivery-for-aws-cdk-applications/) | |
- [Cross-account CI/CD Pipeline with CDK Pipelines](https://catalog.us-east-1.prod.workshops.aws/workshops/874d349f-85f6-495d-9475-ff7b7b23201f/en-US) | |
- [Awesome CDK](https://github.com/kolomied/awesome-cdk) - Curated list of awesome AWS Cloud Development Kit (AWS CDK) open-source projects, guides, blogs and other resources. | |
- [The CDK Book A Comprehensive Guide to the AWS Cloud Development Kit](https://thecdkbook.com/) | |
- [Migrating to AWS CDK v2](https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html) | |
- [Best practices for developing cloud applications with AWS CDK](https://aws.amazon.com/blogs/devops/best-practices-for-developing-cloud-applications-with-aws-cdk/) | |
#### CDK WorkShop | |
- [AWS CDK WorkShop](https://cdkworkshop.com/) | |
#### CDK Pipelines | |
- [Announcing CDK Pipelines Preview, continuous delivery for AWS CDK applications](https://aws.amazon.com/about-aws/whats-new/2020/07/announcing-cdk-pipelines-preview/) | |
- [Continuous integration and delivery (CI/CD) using CDK Pipelines](https://docs.aws.amazon.com/cdk/v2/guide/cdk_pipeline.html) | |
#### CDK Community | |
- [aws/aws-cdk GitHub](https://github.com/aws/aws-cdk) | |
- [cdk.dev Slack channel](https://cdk.dev/) | |
- [StackOverflow Questions tagged aws-cdk](https://stackoverflow.com/questions/tagged/aws-cdk) | |
- [CDK Patterns Twitter](https://twitter.com/CdkPatterns) | |
### TypeScript | |
- [TypeScript](https://www.typescriptlang.org/) | |
- [What is a tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment