|
1 | 1 | # IaC Django Serverless Starter for AWS |
2 | 2 |
|
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). |
4 | 4 |
|
5 | 5 | ## Table of Contents |
6 | 6 |
|
7 | 7 | 1. [Demo](#demo) |
8 | 8 | 2. [Architecture](#architecture) |
9 | 9 | 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) |
14 | 15 |
|
15 | 16 | ## Demo |
16 | 17 |
|
@@ -87,73 +88,99 @@ Ensure the following are installed and configured: |
87 | 88 | 4. [AWS Account](https://aws.amazon.com/) |
88 | 89 | 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)) |
89 | 90 |
|
90 | | -### Launch Locally |
| 91 | +## Development Environment |
91 | 92 |
|
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. |
93 | 94 |
|
94 | | -```sh |
95 | | -git clone https://github.com/efficient-solutions/aws-iac-django-serverless-starter.git |
96 | | -``` |
| 95 | +### Benefits |
97 | 96 |
|
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. |
99 | 101 |
|
100 | | -3. Apply the Django database migration by running the following command in the VS Code terminal: |
| 102 | +### Using Dev Containers |
101 | 103 |
|
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). |
105 | 108 |
|
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. |
107 | 116 |
|
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 |
111 | 136 |
|
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. |
113 | 140 |
|
114 | 141 | ## Usage |
115 | 142 |
|
116 | 143 | ### Build & Deploy |
117 | 144 |
|
118 | 145 | 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: |
119 | 146 |
|
120 | | -#### 1. Build a deployment package |
| 147 | +1. Build a deployment package: |
121 | 148 |
|
122 | | -```sh |
123 | | -sam build |
124 | | -``` |
| 149 | + ```sh |
| 150 | + sam build |
| 151 | + ``` |
125 | 152 |
|
126 | | -#### 2. Deploy the stack and the application |
| 153 | +2. Deploy the stack and the application: |
127 | 154 |
|
128 | | -```sh |
129 | | -sam deploy --guided |
130 | | -``` |
| 155 | + ```sh |
| 156 | + sam deploy --guided |
| 157 | + ``` |
131 | 158 |
|
132 | | -#### 3. Apply the database migrations |
| 159 | +3. Apply the database migrations: |
133 | 160 |
|
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 | + ``` |
137 | 164 |
|
138 | | -#### 4. Collect the static files |
| 165 | +4. Collect the static files: |
139 | 166 |
|
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 | + ``` |
143 | 170 |
|
144 | | -#### 5. Create a superuser |
| 171 | +5. Create a superuser: |
145 | 172 |
|
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 | + ``` |
149 | 176 |
|
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. |
151 | 178 |
|
152 | 179 | ### Launch Remotely |
153 | 180 |
|
154 | 181 | After successfully deploying, you will receive an `HttpApiUrl` output. Open this URL in your browser. |
155 | 182 |
|
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. |
157 | 184 |
|
158 | 185 | ### Clean Up |
159 | 186 |
|
|
0 commit comments