Serverless is toolkit for deploying and operating serverless framework due to focus your application.
In this article, I would like to introduce how to build basic lambda API by Node.js/Python with Docker.
yarn global add serverless
If you want to develop a function with Python, it is better to use Dockerfile, because it is easy to use pip library in lambda.
Dockerfile for development:
After then, create
Please add your AWS Access information and do not commit the
.env.docker file in git repository.
docker-compose up -d
sls config credentials --provider aws --key $AWS_ACCESS_KEY_ID --secret $AWS_SECRET_ACCESS_KEY
Create new service:
# Create service with Python 3.x
serverless.yml configuration file:
diff --no-index --unified=1 serverless.org.yml serverless.yml):
@@ -25,3 +25,3 @@ provider:
Enable to confirm your devloping function on local
# Call the function
After development, you can deploy your code by one command:
sls deploy -v
Enable to confirm your devloping function on local or you can call your API by
# Call the function
If you want to use library, please install pip libraries as follows:
# In docker
You can configure memory size and timeout for function in AWS lambda:
If you want to know more detail, please see https://serverless.com/framework/docs/providers/aws/guide/functions/ .
Please configure including/excluding a file or a folder.
# you can add packaging information here
If you want to know more detail, please see https://serverless.com/framework/docs/providers/aws/guide/packaging/
Enable to configure cron/scheduled job.
# Cron (scheduled job) information
If you want to know more detail, please see https://serverless.com/framework/docs/providers/aws/events/schedule/
My impression for serverless is as follows:
- A deploy command (
serverless deploy) is simple and useful to create the required IAM, set up CloudWatch logs, set up S3 for deployment, deploy, etc.
- Cron (CloudWatch Events) needs just a line to YAML, there are a lot of useful configurations.
- I thought that it was easy for using Google Cloud Function to manage credential on GCP, I tried a little, but it was buggy. I think that serverless is useful in only AWS lambda.
- There are some problems in GCF and serverless. Also, GCF is beta yet.
- I found https://github.com/serverless/serverless-graphql . If it becomes better, it is a good option for GraphQL server.
Node version is 6.14.0, so please be careful: https://cloud.google.com/functions/docs/writing/ .
echo '6.14.0' > .nvmrc
Create a project:
serverless create --template google-nodejs --path gcf-nodejs
Install npm libraries:
# Confirm your code by function
If you want to know more detail, please see https://serverless.com/framework/docs/providers/google/guide/quick-start/ .
- SLA is not guaranteed because it is in beta test.
- It is impossible to configure environment variable like AWS.
- There is no mechanism like cron, scheduled job.
- It is thought that the test with GCP is not done much.
Load and delete a credential data from environment variable in AWS lambda:
🖥 Recommended VPS Service
VULTR provides high performance cloud compute environment for you.
Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour).
In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!