Skip to content

Template to setup AWS lambda (python) + API gateway with Serverless Framework

Notifications You must be signed in to change notification settings

e2fyi/serverless-py-template

Repository files navigation

serverless-aws-py

This repo holds a basic template to deploy python codes to AWS lambda function.

1. Setup

AWS policy for serverless bot

Please create an IAM bot-user in AWS. A default policy for Singapore region can be found in serverless-aws-py-dev-ap-southeast-1-policy.json. You can also generate your own policy with yeoman:

npm run policy

Setup AWS credentials locally

Please ensure your AWS credentials are exported as your current environment variables AWS_KEY and AWS_SECRET respectively. Otherwise you can create an .env file of the form:

AWS_KEY=SOMERANDOMIDKEY
AWS_SECRET=SOMERANDOMSECRETVALUE

Run the following command once to setup your credentials:

npm run init

2. Usage

Setup nodeJS dependencies

npm i

or

yarn

Deploy all functions to AWS

npm run deploy

Deploy specific function to AWS

npm run deployf -- <name of the function>

Remove all and clean functions from AWS

npm run remove

Test locally

npm run function -- <name of the function>
npm run function -- echo --data hello!

Test deployed function

npm run api -- <name of the function>
npm run api -- echo --data hello!

Test api endpoint

You will see the api endpoint after deploying to AWS

curl -d [DATA] -X POST [API_ENDPOINT]

# example
curl -d "hello!" -X POST https://abcdef.execute-api.ap-southeast-1.amazonaws.com/dev/echo

Others

Please look at serverless cli documentation for more details.

As serverless is installed locally, please prefix the command with a npx:

npx serverless

About

Template to setup AWS lambda (python) + API gateway with Serverless Framework

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages