Skip to content

Commit e30e046

Browse files
author
Andrei D.
committed
Add Development Environment section
1 parent 4c40965 commit e30e046

File tree

1 file changed

+69
-42
lines changed

1 file changed

+69
-42
lines changed

README.md

Lines changed: 69 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# IaC Django Serverless Starter for AWS
22

3-
This project demonstrates how to deploy a Django application utilizing a *fully* serverless architecture on AWS. It uses AWS Lambda as the execution environment, SQLite as the database, and CloudFormation/SAM for infrastructure provisioning. The setup includes a local development environment using VS Code and Docker/Devcontainer. Please note that this project is intended for demonstration purposes and is not suitable for production use (see Limitations section).
3+
This project demonstrates how to deploy a Django application utilizing a *fully* serverless architecture on AWS. It uses AWS Lambda as the execution environment, SQLite as the database, and CloudFormation/SAM for infrastructure provisioning. The setup includes a local development environment using VS Code and Docker/Dev Containers. Please note that this project is intended for demonstration purposes and is not suitable for production use (see Limitations section).
44

55
## Table of Contents
66

77
1. [Demo](#demo)
88
2. [Architecture](#architecture)
99
3. [Installation](#installation)
10-
4. [Usage](#usage)
11-
5. [Limitations](#limitations)
12-
6. [License](#license)
13-
7. [Disclaimer](#disclaimer)
10+
4. [Development Environment](#development-environment)
11+
5. [Usage](#usage)
12+
6. [Limitations](#limitations)
13+
7. [License](#license)
14+
8. [Disclaimer](#disclaimer)
1415

1516
## Demo
1617

@@ -87,73 +88,99 @@ Ensure the following are installed and configured:
8788
4. [AWS Account](https://aws.amazon.com/)
8889
5. AWS Credentials ([Single-Sign On](https://aws.amazon.com/iam/identity-center/) or [Access Keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html))
8990

90-
### Launch Locally
91+
## Development Environment
9192

92-
1. Clone this repository:
93+
This project uses VS Code's [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) to provide a consistent and isolated development environment via Docker.
9394

94-
```sh
95-
git clone https://github.com/efficient-solutions/aws-iac-django-serverless-starter.git
96-
```
95+
### Benefits
9796

98-
2. Open the project in a Dev Container in VS Code.
97+
- **Environment Consistency**: All developers use the same environment configuration, reducing "it works on my machine" issues.
98+
- **Simplified Onboarding**: New developers can start quickly without manual setup of dependencies.
99+
- **Isolation**: Dependencies are containerized, avoiding conflicts with the host system.
100+
- **Portability**: The Dev Container configuration can be used across different platforms, ensuring a standardized setup.
99101

100-
3. Apply the Django database migration by running the following command in the VS Code terminal:
102+
### Using Dev Containers
101103

102-
```sh
103-
python src/manage.py migrate
104-
```
104+
1. **Install Prerequisites**:
105+
- Install [Docker Desktop](https://www.docker.com/products/docker-desktop).
106+
- Install [Visual Studio Code](https://code.visualstudio.com/).
107+
- Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).
105108

106-
4. Create a superuser by running the following command in the VS Code terminal:
109+
2. **Open the Project in a Dev Container**:
110+
- Clone the repository:
111+
```sh
112+
git clone https://github.com/efficient-solutions/aws-iac-django-serverless-starter.git
113+
```
114+
- Open the project folder in VS Code.
115+
- Click **Reopen in Container** when prompted. VS Code will build and launch the Dev Container based on the configuration files in the `.devcontainer` folder.
107116

108-
```sh
109-
python src/manage.py createsuperuser
110-
```
117+
3. **Access the Dev Container**:
118+
- The integrated terminal in VS Code is connected to the Dev Container environment, pre-configured with Python, AWS CLI, and other necessary tools.
119+
- Project files are mounted directly into the container, allowing seamless editing and debugging.
120+
121+
4. **Running the Application**:
122+
- Apply Django migrations:
123+
```sh
124+
python src/manage.py migrate
125+
```
126+
- Start the Django server:
127+
```sh
128+
python src/manage.py runserver
129+
```
130+
131+
### Customizing the Dev Container
132+
133+
You can modify the Dev Container setup in `.devcontainer/devcontainer.json`, `.devcontainer/devcontainer.env`, and `.devcontainer/Dockerfile` to include additional tools, environment variables, or extensions.
134+
135+
### Troubleshooting
111136

112-
5. Launch the Django application from the VS Code menu: `Run > Run Without Debugging`.
137+
- **Container Build Issues**: Verify Docker is running with enough allocated resources (memory, CPU).
138+
- **Extension Problems**: Rebuild the container using the command palette (`Dev Containers: Rebuild Container`).
139+
- **Configuration Sync Issues**: If updates to the configuration are not reflected, rebuild the container to refresh the environment.
113140

114141
## Usage
115142

116143
### Build & Deploy
117144

118145
Before proceeding to the deployment, add your [AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-authentication.html) to the current environment. Then, execute the following commands in the VS Code terminal:
119146

120-
#### 1. Build a deployment package
147+
1. Build a deployment package:
121148

122-
```sh
123-
sam build
124-
```
149+
```sh
150+
sam build
151+
```
125152

126-
#### 2. Deploy the stack and the application
153+
2. Deploy the stack and the application:
127154

128-
```sh
129-
sam deploy --guided
130-
```
155+
```sh
156+
sam deploy --guided
157+
```
131158

132-
#### 3. Apply the database migrations
159+
3. Apply the database migrations:
133160

134-
```sh
135-
sam remote invoke Function --event '{"manage":"migrate"}' --stack-name aws-iac-django-serverless-starter
136-
```
161+
```sh
162+
sam remote invoke Function --event '{"manage":"migrate"}' --stack-name aws-iac-django-serverless-starter
163+
```
137164

138-
#### 4. Collect the static files
165+
4. Collect the static files:
139166

140-
```sh
141-
sam remote invoke Function --event '{"manage":"collectstatic"}' --stack-name aws-iac-django-serverless-starter
142-
```
167+
```sh
168+
sam remote invoke Function --event '{"manage":"collectstatic"}' --stack-name aws-iac-django-serverless-starter
169+
```
143170

144-
#### 5. Create a superuser
171+
5. Create a superuser:
145172

146-
```sh
147-
sam remote invoke Function --event '{"manage":"create_superuser"}' --stack-name aws-iac-django-serverless-starter
148-
```
173+
```sh
174+
sam remote invoke Function --event '{"manage":"create_superuser"}' --stack-name aws-iac-django-serverless-starter
175+
```
149176

150-
> This command creates a superuser `root` with a randomly-generated password which is returned in the output. Change this password once you log in. Also, this command can only be run once.
177+
> **Important**: This command creates a superuser `root` with a randomly-generated password which is returned in the output. Change this password once you log in. Also, this command can only be run once.
151178

152179
### Launch Remotely
153180

154181
After successfully deploying, you will receive an `HttpApiUrl` output. Open this URL in your browser.
155182

156-
> Due to the limitations of static serving from the Lambda function, it may take several minutes after running the `collectstatic` command before all static files are available. During this time, you may encounter occasional HTTP 404 errors.
183+
> **Note:** Due to the limitations of static serving from the Lambda function, it may take several minutes after running the `collectstatic` command before all static files are available. During this time, you may encounter occasional HTTP 404 errors.
157184

158185
### Clean Up
159186

0 commit comments

Comments
 (0)