| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
Install Serverless
npm install -g serverless
Install serverless-python-requirements
npm i --save serverless-python-requirements
Define necessary environment variables
Append this to your ~/.bash_profile
export MONGO_DB_USER= export MONGO_DB_PASS= export MONGO_DB_NAME=SampleDatabase export MONGO_COLLECTION_NAME=SampleCollection export MONGO_DB_URL=
Deploy the API
sls deploy
Your results should look something like this:
Serverless: Stack update finished...
Service Information
service: serverless-pymongo-item-api
stage: dev
region: us-east-1
stack: serverless-pymongo-item-api-dev
resources: 28
api keys:
None
endpoints:
POST - https://0xfyi15qci.execute-api.us-east-1.amazonaws.com/dev/item
GET - https://0xfyi15qci.execute-api.us-east-1.amazonaws.com/dev/item
GET - https://0xfyi15qci.execute-api.us-east-1.amazonaws.com/dev/item/{id}
DELETE - https://0xfyi15qci.execute-api.us-east-1.amazonaws.com/dev/item/{id}
functions:
create: serverless-pymongo-item-api-dev-create
list: serverless-pymongo-item-api-dev-list
get: serverless-pymongo-item-api-dev-get
delete: serverless-pymongo-item-api-dev-delete
layers:
None
Serverless: Removing old service artifacts from S3...
Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing.
Substitute your endpoints into these curl commands to test the Create, Read, and Delete operations
curl --request POST \
--url https://0xfyi15qci.execute-api.us-east-1.amazonaws.com/dev/item \
--header 'content-type: application/json' \
--data '{
"attribute_1": "Pet",
"attribute_2": "Rock"
}'
204 status
{
"_id": "c6f03ca0-f792-11e9-9534-260a4b91bfe9",
"data": {
"attribute_1": "Pet",
"attribute_2": "Rock"
}
}
curl --request GET \ --url https://0xfyi15qci.execute-api.us-east-1.amazonaws.com/dev/item/c6f03ca0-f792-11e9-9534-260a4b91bfe9 \ --header 'content-type: application/json'
200 status
{
"_id": "c6f03ca0-f792-11e9-9534-260a4b91bfe9",
"data": {
"attribute_1": "Pet",
"attribute_2": "Rock"
}
}
curl --request GET \ --url https://0xfyi15qci.execute-api.us-east-1.amazonaws.com/dev/item \ --header 'content-type: application/json'
200 status
{
"response_items": [
{
"_id": "c6f03ca0-f792-11e9-9534-260a4b91bfe9",
"data": {
"attribute_1": "Pet",
"attribute_2": "Rock"
}
},
{
"_id": "717c5f36-f799-11e9-a921-1e0e685be73c",
"data": {
"attribute_1": "Pete",
"attribute_2": "Rock"
}
}
],
"filter": null
}
curl --request DELETE \ --url https://0xfyi15qci.execute-api.us-east-1.amazonaws.com/dev/item/c6f03ca0-f792-11e9-9534-260a4b91bfe9 \ --header 'content-type: application/json'
204 status
| Back | FazBrowse Home | New Git URL |