-
Notifications
You must be signed in to change notification settings - Fork 0
/
important_commands.sh
117 lines (82 loc) · 3.33 KB
/
important_commands.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
################################################################################
# PART 1: Configure NodeJs, Python and CDK libraries
################################################################################
# Install NodeJs and Python
# --> https://nodejs.org/en/download/
# --> https://www.python.org/downloads/
# Verify that NodeJs/npm is installed correctly
node --version
npm --version
# Verify that Python/pip is installed correctly
python --version || python3 --version
pip --version || pip3 --version
# Install AWS-CDK (on NodeJs)
sudo npm install -g aws-cdk
# Verify correct install of AWS-CDK
npm list --global | grep aws-cdk
# Install AWS construct library on Python
pip install aws-cdk-lib
################################################################################
# PART 2: Initial Project Setup (Only run these at the beginning)
################################################################################
# Configure AWS credentials (follow steps)
aws configure
# Bootstrap CDK (provision initial resources to work with CDK.. S3, roles, etc)
#! Change "ACCOUNT-NUMBER-1" and "REGION-1" to your needed values
cdk bootstrap aws://ACCOUNT-NUMBER-1/REGION-1
# Create the CDK project's folder
mkdir cdk
cd cdk || echo "Make sure that the folder exists"
# Initialize project
cdk init --language python
# If the virtual environment didn't create, do it manually
python3 -m venv ./.venv
# Access the virtual environment and install its dependencies
source .venv/bin/activate || echo "Make sure that virtual env exists"
pip install -r requirements.txt || pip3 install -r requirements.txt
################################################################################
# PART 3: Main CDK commands (most used)
################################################################################
cdk bootstrap
# Setup environment (choose one)
export ENVIRONMENT="dev"
export ENVIRONMENT="prod"
# Storage Stack RDS
cdk synthesize --app "python3 app_storage_rds.py"
cdk diff --app "python3 app_storage_rds.py"
cdk deploy --app "python3 app_storage_rds.py"
cdk destroy --app "python3 app_storage_rds.py"
# Compute Stack API-Lambda (requires Storage Stacks already deployed)
cdk synthesize --app "python3 app_compute_api_lambda.py"
cdk diff --app "python3 app_compute_api_lambda.py"
cdk deploy --app "python3 app_compute_api_lambda.py"
cdk destroy --app "python3 app_compute_api_lambda.py"
################################################################################
# PART 4: Other CDK usefull commands
################################################################################
# Help
cdk --help
cdk deploy --help
# Lists the stacks in the app
cdk list
# Synthesizes and prints the CloudFormation template for the specified stack(s)
cdk synthesize
# Deploys the CDK Toolkit staging stack (necessary resources in AWS account)
cdk bootstrap
# Deploys the specified stack(s)
cdk deploy
# Destroys the specified stack(s)
cdk destroy
# Compares the specified stack with the deployed stack or a local CloudFormation template
cdk diff
# Displays metadata about the specified stack
cdk metadata
# Creates a new CDK project in the current directory from a specified template
cdk init
# Manages cached context values
cdk context
# Opens the CDK API reference in your browser
cdk docs
# Checks your CDK project for potential problems
cdk doctor