Before starting up this project, make sure you have an AWS account.
-
AWS Command Line Interface - The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services.
-
Pulumi - Universal Infrastructure as Code
- Installing Python Packages
$ pip install -r requirements.txt
- Note: For our project we are using db.sqlite3. I strongly recommend to use Postgres/MySQL when setting up in production.
Login to Pulumi and create a new project.
Make sure to name the stack as aws-python.
Update the respective YAML files & django settings in the codebase.
Pulumi.yaml
settings.py
Run the below command :
- pulumi login
Run the below command :
- python manage.py migrate
Run the below command :
- python manage.py createsuperuser
Make sure to update your AWS credentials, residing in $HOME/.aws/credentials
- Note: For this demo, make sure the IAM User should have AdministratorAccess. This is not recommended permission you need to give. Kindly, follow the security best practices.
[default]
aws_access_key_id = xxxxxxxxxxxxxxxxxxxxx
aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxx
Run the below command :
- python manage.py load_resources
This command is going to dump all the AWS resources into your database.
- VPC
- Subnets
- Security Groups
- Key Pair
- Instance Types
Provide the superuser credentials, which you have created recently.
You can now observe that all the AWS information has been dumped in our database, and it's reflected in the admin.
We will provide all the necessary information for creating EC2 Instance.
- Note: Pulumi will be invoked in the foreground, I recommend using background tasks like Celery & RabbitMQ
You can see below, that the instance has been created and the Public IPv4 address has been updated.
Now, we will go ahead and delete the instance information from Django Admin
You can observe the django console, that Pulumi has started the process to terminate the instance.
If you are interested to know more about Pulumi.