-
Notifications
You must be signed in to change notification settings - Fork 0
/
important_commands.sh
115 lines (80 loc) · 3.16 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
#!/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"
# Create Python virtual environment
python3 -m venv .venv
# Initialize project
cdk init --language python
# 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
source .venv/bin/activate || echo "Make sure that virtual env exists"
# Test Lambda Python Stack
python -m pytest
# Important: install Python dependencies on Lambda Layer (ONLY REFLECTED IN LOCAL COMPUTER, NOT IN GITHUB)
# --> Note: this should be run at the root of the repository (./)
# pip install beautifulsoup4 urllib3 --target=./lambda/layer/python
# Lambda Python Stack
cdk synthesize
cdk diff
cdk deploy
cdk destroy
################################################################################
# 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