首页 > 其他 > 详细

[Serverless CLI + AWS] Get started with Serverless and AWS lambda

时间:2021-02-24 23:48:34      阅读:29      评论:0      收藏:0      [点我收藏+]

Serverless AWS lambda

Install

npm install -g serverless

Config serverless with aws

serverless config credentials --provider aws --key <ACCESS_KEY_AWS> --secret <SECRET_KEY_AWS>

Init project

serverless create --template aws-nodejs --name cake-ordering-system

Define how to trigger lambda in serverless.yml

for example:

functions:
  createOrder:
    handler: handler.createOrder
    # trigger for lambda
    events:
      # http: stands for APIGateWay
      - http:
          path: /order
          method: post

Hanlder

In handler.js:

"use strict";

module.exports.createOrder = async (event) => {
  return {
    statusCode: 200,
    body: JSON.stringify({
      message: "Create Order",
      input: event,
    }),
  };
};

Deploy

sls deploy

[Serverless CLI + AWS] Get started with Serverless and AWS lambda

原文:https://www.cnblogs.com/Answer1215/p/14443931.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!