- Prerequisites
- Environment setup
- Deployment
- Launching and stopping the application in offline mode
- Run demo script
- cURL examples
- Application removal
- Stopping container
Small demo application which incorporates AWS API Gateway and several AWS Lambdas behind it. It's deployment has been tested with macOS, but should work under Linux & Windows as well.
The following software is to be installed to start:
python
>= 3.8pipenv
docker
&docker-compose
(Linux or macOS. In Windows minor changes needed.)
$ cd [repo root directory]
$ pipenv --python 3.8
$ pipenv shell
$ pipenv sync
$ pipenv sync --dev
$ inv -l
>>
Available tasks:
local.autopep8 >> Run autocorrection on python files.
serverless.deploy >> Deploy serverless application.
serverless.info >> Serverless application status info. Including endpoints and api token.
serverless.offline >> Run serverless application in offline mode.
serverless.rebuild-container >> Build and run build container.
serverless.remove >> Remove serverless application.
serverless.stop-container >> Stop and remove sls container.
$ export AWS_REGION="[region here]"
$ export AWS_ACCESS_KEY_ID="[access key id here]"
$ export AWS_SECRET_ACCESS_KEY="[secret access key here]"
$ docker ps
>>
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ inv serverless.rebuild-container
$ inv serverless.deploy
$ inv serverless.offline
$ curl localhost:3000
>>
{
"currentRoute": "get - /",
"error": "Serverless-offline: route not found.",
"existingRoutes": [
"post - /prod/poc/create_s3_bucket",
"get - /prod/poc/list_s3_bucket/{bucket_name}",
"post - /prod/poc/upload_to_s3_bucket"
],
"statusCode": 404
}
$ inv serverless.stop-container
$ inv serverless.offline
This will do the following:
- Create s3 bucket
- Generate several random files
- Upload them concurrently to s3
- In order to utilize API Gateway and Lambdas, set the proper endpoint and token (env: TEST_POC_API_KEY, env: BASE_URL).
They can be found in the output of
inv serverless.info
command.
$ python demo.py
NB: do not forget to remove test s3 bucket after performing tests!
- In the offline mode:
$ curl -X POST http://localhost:3000/prod/poc/create_s3_bucket -H 'x-api-key: <fake key>' --data '{"region": "us-east-1", "bucket_name": "uniqnamedbucket"}'
$ curl -X POST http://localhost:3000/prod/poc/upload_to_s3_bucket -H 'x-api-key: <fake key>' --data '{"bucket_name": "uniqnamedbucket"}'
$ curl -X GET http://localhost:3000/prod/poc/list_s3_bucket/uniqnamedbucket -H "x-api-key: <fake key>"
- Utilizing real API Gateway:
$ curl -X POST https://[API GATEWAY ENDPOINT]/prod/poc/create_s3_bucket -H 'x-api-key: <real key>' --data '{"region": "us-east-1", "bucket_name": "uniqnamedbucket"}'
$ curl -X POST https://[API GATEWAY ENDPOINT]/prod/poc/upload_to_s3_bucket -H 'x-api-key: <real key>' --data '{"bucket_name": "uniqnamedbucket"}'
$ curl -X GET https://[API GATEWAY ENDPOINT]/prod/poc/list_s3_bucket/uniqnamedbucket -H "x-api-key: <real key>"
$ inv serverless.remove
$ inv serverless.stop-container