Skip to content

Commit

Permalink
Update documentation, add dokcer compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Hatter1337 committed Aug 13, 2024
1 parent 7902cff commit 1578f98
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ This project demonstrates serverless architecture, offering scalable and cost-ef

**Note:** `swagger.yml` and Postman collection are located in the `/doc` directory.

## Project structure
- `/docs` - API documentation with swagger file
- `/src` - Source code
- `/lambda` - Code base related to Lambda functions
- `/functions` - Lambda functions
- `/{name}` - Specific Lambda function with `handler.py`
- `/tests` - Unit tests for all Lambda functions
- `/layers` - Code base related to Lambda layers
- `/{name}_layer` - Lambda layer with `requirements.txt` and common code
- `/tests` - Unit tests for all Lambda layers
- `/resources` - AWS resources configuration with CloudFormation
- `template.yaml` - SAM template file with API resources: API Gateway, Lambda functions, etc.
- `samconfig.toml` - SAM configuration file with environment variables and parameters
- `docker-compose.yaml` - Docker Compose configuration for local development
- `run-local-api.sh` - Script to run SAM application locally in Docker

## Deploy to your AWS account
- First of all, you need to have an AWS account and AWS CLI installed on your machine.
- Clone this repository and navigate to the root directory.
Expand All @@ -24,8 +40,17 @@ This project demonstrates serverless architecture, offering scalable and cost-ef
$ sam build
$ sam deploy --config-env dev --profile {your-aws-profile}
```
- Or run locally using **SAM CLI**:

## Run locally using **SAM**:
- Configure your AWS CLI with the necessary credentials, for your AWS profile, before running SAM commands.
- Ensure Docker is running for `sam local start-api` to simulate the Lambda environment.
- Run the following commands to build and start the API locally:
```bash
$ sam build
$ sam local start-api
```
$ sam local start-api --port 8000 --profile {your-aws-profile}
```

You also can use Dokcer Compose to run the application locally:
- Change the AWS profile name in `run-local-api.sh`.
- Grant execution rights to the script: `$ chmod +x run-local-api.sh`
- `$ docker-compose up`
12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
sam:
image: public.ecr.aws/sam/build-python3.12:1.112.0-20240313001228
container_name: pokemon-api-local
ports:
- "8000:8000"
volumes:
- .:$PWD
- /var/run/docker.sock:/var/run/docker.sock
- ~/.aws/:/root/.aws:ro
working_dir: $PWD
entrypoint: ["/bin/sh", "-c", "./run-local-api.sh"]
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions run-local-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

sam build

sam local start-api \
--profile {your-aws-profile} \
--container-host host.docker.internal \
--skip-pull-image \
--host 0.0.0.0 \
--port 8000 \
--container-host-interface 0.0.0.0

0 comments on commit 1578f98

Please sign in to comment.