https://github.com/martinsmessias/serverless_api_crud_aws
API Gateway + Lambda + DynamoDB + Serverless Framework + Python + Actions
https://github.com/martinsmessias/serverless_api_crud_aws
actions api-gateway dynamodb lambda python serverless
Last synced: 5 months ago
JSON representation
API Gateway + Lambda + DynamoDB + Serverless Framework + Python + Actions
- Host: GitHub
- URL: https://github.com/martinsmessias/serverless_api_crud_aws
- Owner: MartinsMessias
- Created: 2022-02-20T17:16:07.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-27T14:41:34.000Z (over 4 years ago)
- Last Synced: 2025-05-30T19:28:50.668Z (about 1 year ago)
- Topics: actions, api-gateway, dynamodb, lambda, python, serverless
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://github.com/MartinsMessias/serverless_api_crud_aws/actions/workflows/aws.yml)
# Serverless Framework Python HTTP API on AWS
## Usage
### Deployment
```
$ serverless deploy
```
After deploying, you should see output similar to:
```bash
Deploying aws-python-http-api-project to stage dev (us-east-1)
✔ Service deployed to stack aws-python-http-api-project-dev (140s)
endpoint: GET - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/
functions:
hello: aws-python-http-api-project-dev-hello (2.3 kB)
```
_Note_: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to [http event docs](https://www.serverless.com/framework/docs/providers/aws/events/apigateway/).
### Invocation
After successful deployment, you can call the created application via HTTP:
```bash
curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/
```
Which should result in response similar to the following (removed `input` content for brevity):
```json
{
"message": "Go Serverless v3.0! Your function executed successfully!",
"input": {
...
}
}
```
### Local development
You can invoke your function locally by using the following command:
```bash
serverless invoke local --function hello
```
Which should result in response similar to the following:
```
{
"statusCode": 200,
"body": "{\n \"message\": \"Go Serverless v3.0! Your function executed successfully!\",\n \"input\": \"\"\n}"
}
```
Alternatively, it is also possible to emulate API Gateway and Lambda locally by using `serverless-offline` plugin. In order to do that, execute the following command:
```bash
serverless plugin install -n serverless-offline
```
It will add the `serverless-offline` plugin to `devDependencies` in `package.json` file as well as will add it to `plugins` in `serverless.yml`.
After installation, you can start local emulation with:
```
serverless offline
```
To learn more about the capabilities of `serverless-offline`, please refer to its [GitHub repository](https://github.com/dherault/serverless-offline).
### Bundling dependencies
In case you would like to include 3rd party dependencies, you will need to use a plugin called `serverless-python-requirements`. You can set it up by running the following command:
```bash
serverless plugin install -n serverless-python-requirements
```
Running the above will automatically add `serverless-python-requirements` to `plugins` section in your `serverless.yml` file and add it as a `devDependency` to `package.json` file. The `package.json` file will be automatically created if it doesn't exist beforehand. Now you will be able to add your dependencies to `requirements.txt` file (`Pipfile` and `pyproject.toml` is also supported but requires additional configuration) and they will be automatically injected to Lambda package during build process. For more details about the plugin's configuration, please refer to [official documentation](https://github.com/UnitedIncome/serverless-python-requirements).