zoukankan      html  css  js  c++  java
  • 如何用serverless创建aws-lambda

    https://serverless.com/framework/docs/providers/aws/guide/quick-start/

    安装serverless

    $npm install -g serverless

    $mkdir serverless-demo

    $cd serverless-demo/

    $serverless create -t aws-nodejs

    从aws里找到"My Security Credentials'

    https://serverless.com/framework/docs/providers/aws/guide/credentials/#create-an-iam-user-and-access-key


    Add credential to your local laptop:

    $serverless config credentials --provider aws --key AKIAIDEXAZA --secret xxxEL5xFZYxxx49nuu

    $cat ~/.aws/credentials 

    接下来打开demo文件,编辑serverless.yml:

    service: lambda-test
    provider:
      name: aws
      runtime: nodejs10.x
    functions:
      hello:
        handler: handler.hello
        events:
          - http:
              path: users/create
              method: get
      imageResize:
        handler: handler.imageResize
        events:
          - http:
              path: /imageResize
              method: get
    

      

    编辑handel.js

    'use strict';
    
    module.exports.hello = async event => {
      return {
        statusCode: 200,
        body: JSON.stringify(
          {
            message: 'This is v1.0',
          },
          null,
          2
        ),
      };
    };
    
    module.exports.imageResize = async event => {
      return {
        statusCode: 200,
        body: JSON.stringify(
          {
            message: 'resized your image',
          },
          null,
          2
        ),
      };
    };
    

      

    保存修改之后, 发布到测试环境

    $serverless deploy

    Serverless: Packaging service...

    Serverless: Excluding development dependencies...

    Serverless: Uploading CloudFormation file to S3...

    Serverless: Uploading artifacts...

    Serverless: Uploading service lambda-test.zip file to S3 (417 B)...

    Serverless: Validating template...

    Serverless: Updating Stack...

    Serverless: Checking Stack update progress...

    ................................

    Serverless: Stack update finished...

    Service Information

    service: lambda-test

    stage: dev

    region: us-east-1

    stack: lambda-test-dev

    resources: 17

    api keys:

      None

    endpoints:

      GET - https://xxx.execute-api.us-east-1.amazonaws.com/dev/users/create

      GET - https://xxx.execute-api.us-east-1.amazonaws.com/dev/imageResize

    functions:

      hello: lambda-test-dev-hello

      imageResize: lambda-test-dev-imageResize

    layers:

      None

    Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing.

    发布到正式环境的命令:

    $ serverless deploy --stage production

    Serverless: Packaging service...

    Serverless: Excluding development dependencies...

    Serverless: Creating Stack...

    Serverless: Checking Stack create progress...

    .....

    Serverless: Stack create finished...

    Serverless: Uploading CloudFormation file to S3...

    Serverless: Uploading artifacts...

    Serverless: Uploading service lambda-test.zip file to S3 (417 B)...

    Serverless: Validating template...

    Serverless: Updating Stack...

    Serverless: Checking Stack update progress...

    ...................................................

    Serverless: Stack update finished...

    Service Information

    service: lambda-test

    stage: production

    region: us-east-1

    stack: lambda-test-production

    resources: 17

    api keys:

      None

    endpoints:

      GET - https://xxx.execute-api.us-east-1.amazonaws.com/production/users/create

      GET - https://xxx.execute-api.us-east-1.amazonaws.com/production/imageResize

    functions:

      hello: lambda-test-production-hello

      imageResize: lambda-test-production-imageResize

    layers:

      None

    Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing.

  • 相关阅读:
    【公告】对乐逍遥和王者之剑利用破解程序插入刷流量广告处理结果
    Thunder7.2.13.3884 JayXon
    免费获取半年 Bitdefender Total Security 2014
    WIN8.1 PRO RTM VOL.2013.09.18
    免费一年MAP2014+6个月免费MIS2014
    大蜘蛛9.0正式版
    腾讯控股涉足商业银行 微信或成先头兵
    植物大战僵尸2:奇妙时空之旅[官方安卓简体中文高清版]有内含....
    苹果iPhone 5C和5S发布后,消费者如何选择?
    pandas中DataFrame操作(一)
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/11312908.html
Copyright © 2011-2022 走看看