Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swiftsoftwaregroup/aws-ec2-cdk-python
Deploy EC2 instance with AWS CDK for Python
https://github.com/swiftsoftwaregroup/aws-ec2-cdk-python
Last synced: 4 days ago
JSON representation
Deploy EC2 instance with AWS CDK for Python
- Host: GitHub
- URL: https://github.com/swiftsoftwaregroup/aws-ec2-cdk-python
- Owner: swiftsoftwaregroup
- License: apache-2.0
- Created: 2024-07-31T22:45:30.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-08-03T17:35:15.000Z (3 months ago)
- Last Synced: 2024-08-03T18:49:50.698Z (3 months ago)
- Language: Python
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ec2-aws-cdk-python
Deploy EC2 instance using the AWS CDK for Python
## Setup for macOS
Make sure you do this setup first:
1. [Setup macOS for AWS Cloud DevOps](https://blog.swiftsoftwaregroup.com/setup-macos-for-aws-cloud-devops)
2. [AWS Authentication](https://blog.swiftsoftwaregroup.com/aws-authentication)
3. [Install AWS CDK on macOS](https://blog.swiftsoftwaregroup.com/install-aws-cdk-macos)
4. For Python support, install `pyenv`:```bash
brew install pyenv
```## Development
Configure project:
```bash
source configure.sh
```Open in Visual Studio Code:
```bash
code .
```### Deploy
Print the CloudFormation template for the stack. You should see the CloudFormation template without any errors:
```bash
cdk synth --profile default
```
Bootstrap the CDK environment. This should be done only once per account. Skip this step if you have done it already. See [Bootstrapping](https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html) for details:```bash
cdk bootstrap --profile default
```
Deploy the stack:```bash
cdk deploy --profile default
```### Test Deployment
Check that you can browse the `nginx` default site:
```bash
key="aws-ec2-key"
instance="NginxEc2Stack/NginxInstance"instance_public_ip=$(aws ec2 describe-instances \
--filters \
Name=tag:Name,Values=$instance \
Name=instance-state-name,Values=running \
| jq -r '.Reservations[0].Instances[0].PublicIpAddress')open http://$instance_public_ip
```### Cleanup
```bash
cdk destroy --profile default
```**Opptional**: To delete the `CDKToolkit` CloudFormation template which is created by the AWS CDK during bootstrap:
```bash
aws cloudformation delete-stack --stack-name CDKToolkit --profile default
```The bootstrap process creates an S3 Bucket with a name: `cdk--assets--`. This bucket will not be deleted automatically and will remain in your account if not deleted manually.
## How to create a new project
```bash
# Node.js
nvm use 20.16.0# Python
mkdir ec2-aws-cdk-python
cd ec2-aws-cdk-python
cdk init app --language python --generate-onlymv README.md README_MDK.md
```