【问题标题】:Serverless Deployment API Gateway with Lambda Integration具有 Lambda 集成的无服务器部署 API 网关
【发布时间】:2019-02-20 07:31:21
【问题描述】:

我正在尝试使用 API 网关 lambda 集成部署 lambda 函数。我的 api 规范是在一个外部 yml 文件中用 openAPI 3 编写的。

我想将 lambda 的 arn 名称传递给 api 规范。

我的 serverless.yml:

service: my-test-service
provider:
  name: aws
  runtime: java8

functions:
  mylambda-test:
    handler: com.sample.MyHandler
    name: mylambda-test
    description: test lambda with api gateway
    package:
      artifact: myexample-1.0-SNAPSHOT-jar-with-dependencies.jar
          individually: true
resources:
  Resources:
    ApiGatewayRestApi:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: test-api
        Body:
          ${file(api.yml)}

在 api.yml:

openapi: "3.0.1"
info:
  title: "test-api"
  version: "0.0.1-oas3"

paths:
  /test:
     get:
       *
       *
       *
        x-amazon-apigateway-integration: 
          uri: {arn of mylambda-test}

【问题讨论】:

标签: amazon-web-services aws-lambda swagger serverless openapi


【解决方案1】:

如何使用endly e2e runner 来部署和设置您的 API 网关

部署工作流程可能如下所示

pipeline:
  setupFunction1:
    action: aws/lambda:deploy
    credentials: $awsCredentials
    functionname: $functionName1
    runtime:  go1.x
    handler: loginfo
    code:
      zipfile: $LoadBinary(${codeZip})
    rolename: lambda-loginfo-executor
    define:
      - policyname: s3-${functionName}-role
        policydocument: $Cat('${privilegePolicy}')
    attach:
      - policyarn: arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

  setupFunction2:
    action: aws/lambda:deploy
    credentials: $awsCredentials
    functionname: $functionName2
    runtime:  go1.x
    handler: loginfo
    code:
      zipfile: $LoadBinary(${codeZip})
    rolename: lambda-loginfo-executor
    define:
      - policyname: s3-${functionName}-role
        policydocument: $Cat('${privilegePolicy}')
    attach:
      - policyarn: arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

  setupAPI:
    action: aws/apigateway:setupRestAPI
    credentials: aws
    '@name': loginfoAPI
    resources:
      - path: /path1
        methods:
          - httpMethod: ANY
            functionname: $functionName1
      - path: /path2
          methods:
              - httpMethod: ANY
                functionname: $functionName2    
  sleepTimeMs: 15000
  post:
  endpointURL: ${setupAPI.EndpointURL}

这是部署示例workflow

您还可以查看使用 lambda 实现 e2e 测试的实际示例,包括 API Gateway

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-10
    • 2019-10-06
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    • 2018-08-27
    • 1970-01-01
    相关资源
    最近更新 更多