I have repalce some URL, username, password or key in the source file, If your want to run the code, please replace those code with yours.
- Severless Framework basic setting
- react basic setting
- MongoDB altas basic operation
npm install -g serverless
- Detail -> Access type: Programmaic access
- Permissions -> Attach existing policies directly: AdministratorAccess
- Create user
- Download csv to save the credential file (Access key ID & Secret access key)
serverless config credentials --provider aws --key <Access key ID> --secret <Secret access key> --profile <IAM name>
serverless create --template aws-python3 --path myService
- change dir
cd myService
- serverless.yml
provider:
name: aws
runtime: python3.6
region: ap-southeast-2 # Sydney
profile: <IAM-user name>
functions:
hello:
handler: handler.hello
- handler.py
import json
def hello(event, context):
print("Hello World")
return "Hello World"
sls deploy -v
sls invoke -f hello -l
return:
"Hello World"
--------------------------------------------------------------------
START RequestId: ******************* Version: $LATEST
Hello World
END RequestId: *******************
REPORT RequestId: *************** Duration: 0.30 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 23 MB
sls deploy function -f hello
sls logs -f hello -t
sls remove
!!! remove everthing !!!
The severless Command Line functionalities can be also achieved in the AWS console
install the plugin
npm install --save serverless-python-requirements
and add the plugin to your serverless.yml
plugins:
- serverless-python-requirements
Don't forget to make sure you have a requirements.txt file.
That's it, once sls deploy is called the plugin will package the dependencies with the code.
I'm lazy, Highly recommand this video https://www.youtube.com/watch?v=uextYhQGP6k&t=6s
If you want to try MongoDB Altas, here is the Documentation https://docs.mongodb.com/
MongoDB provides multi language driver https://docs.mongodb.com/ecosystem/drivers/
try the python file under /db, give you some basic function to play with your data.