Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 如何在AWS代码管道中自动部署api网关_Amazon Web Services_Aws Api Gateway_Amazon Cloudformation_Aws Codepipeline_Aws Codebuild - Fatal编程技术网

Amazon web services 如何在AWS代码管道中自动部署api网关

Amazon web services 如何在AWS代码管道中自动部署api网关,amazon-web-services,aws-api-gateway,amazon-cloudformation,aws-codepipeline,aws-codebuild,Amazon Web Services,Aws Api Gateway,Amazon Cloudformation,Aws Codepipeline,Aws Codebuild,目前,我可以通过推到github来部署lambda。我还自动部署lambda,但这仅仅是因为api网关是lambda yaml文件中的一个事件 AWSTemplateFormatVersion: '2010-09-09' Transform: 'AWS::Serverless-2016-10-31' Description: Identifies paragraphs in documents and links to the law Resources: LambdaParagraphLi

目前,我可以通过推到github来部署lambda。我还自动部署lambda,但这仅仅是因为api网关是lambda yaml文件中的一个事件

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Identifies paragraphs in documents and links to the law
Resources:
  LambdaParagraphLinker:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: LambdaParagraphLinker.lambda_handler
      Runtime: python3.6
      CodeUri: ./
      Description: Identifies paragraphs in documents and links to the 
      law
       MemorySize: 512
      Timeout: 10      
      Events:
        Api:
          Type: Api
          Properties:
            Path: /LambdaParagraphLinker
            Method: ANY

如何使用swagger文件部署api网关?

AWS::Serverless::api


到处都可以找到招摇过市的文档,API网关扩展的文档在开发者指南中。我首先进入API网关控制台,看看Lambda为您创建的API。您可以转到“阶段”页面,对于任何阶段,您都可以将API作为Swagger导出。

AWS::Serverless::API


到处都可以找到招摇过市的文档,API网关扩展的文档在开发者指南中。我首先进入API网关控制台,看看Lambda为您创建的API。您可以转到“阶段”页面,对于任何阶段,您都可以将API作为Swagger导出。

在codepipeline中实现这一点的最佳方法是使用framework。这取代了我以前使用过的每一个超级复杂的黑客工作和变通方法。不那么复杂

创建一个代码管道,将其链接到src&一个代码构建项目,设置一些权限,完成

//serverless.yml

service: my-api
provider:
  name: aws
  runtime: python2.7

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: api/v1/message
          method: post
//buildspec.yml

version: 0.2
phases:
  install:
    commands:
      #BUILD
      - sudo apt-get update -y
  build:
    commands:
      - echo $environment
      - serverless package --stage $environment --region us-east-1
      - serverless deploy --stage $environment --region us-east-1
version: 0.1
phases:
  install:
    commands:
      #BUILD
      - zip -r lambda.zip . -x *.git*
artifacts:
  files:
    - '**/*.zip'
    - '**/*.yml'
  discard-paths: no
或者做下面的一个选择来折磨自己

您可以在代码管道中的cloudformation中执行此操作。从gatewayapi控制台中导出swagger规范并放入cloudformation模板中

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  PlayersAPI:
    Type: AWS::ApiGateway::RestApi
    Properties:
      Name: MyApi
      Description: API Description
      Body:
       "SWAGGER HERE"
将此连接到lambda有点麻烦,但我可以描述步骤。首先创建一个带有源代码、构建和部署步骤的codepipeline项目

  • src应该是github或codecommit的标准配置
  • build应该输出一个zip文件,并使用buildspec.yml之类的东西
//buildspec.yml

version: 0.2
phases:
  install:
    commands:
      #BUILD
      - sudo apt-get update -y
  build:
    commands:
      - echo $environment
      - serverless package --stage $environment --region us-east-1
      - serverless deploy --stage $environment --region us-east-1
version: 0.1
phases:
  install:
    commands:
      #BUILD
      - zip -r lambda.zip . -x *.git*
artifacts:
  files:
    - '**/*.zip'
    - '**/*.yml'
  discard-paths: no
让构建步骤导出工件MyAppBuild(或任何您想称之为MyAppBuild的东西)

最后一个管道步骤是通过控制台(其可重用)将此repo中的lambda函数创建为独立函数:

此lambda函数下载管道工件/压缩lambda函数,并使用boto对其进行更新

在这些步骤之后,您可以添加另一个步骤作为cloudformation部署步骤。将其连接到刚刚部署的lambda函数

如果要处理多个环境,可以为每个环境创建lambda函数和gatewayapi cloudformation模板,然后依次运行它们

  • 第一阶段:src
  • 第2阶段:构建
  • 阶段3:部署lambda测试,部署网关api云形成测试
  • 阶段4:验证测试
  • 第5阶段:部署lambda prod,部署网关api cloudformation prod
像这样直接使用AWS服务器也可以。但是,您需要为uri使用标准工件位置。API的定义URI:可以是从gatewayapi控制台导出的炫耀

//cloudformation.yml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  MySimpleFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: app.lambda_handler
      Runtime: python2.7
      CodeUri: s3://somebucket/somezip.zip
  MyAPI:
     Type: AWS::Serverless::Api
     Properties:
        StageName: prod
        DefinitionUri: s3://somebucket/somezip.zip

在codepipeline中实现这一点的最佳方法是使用框架。这取代了我以前使用过的每一个超级复杂的黑客工作和变通方法。不那么复杂

创建一个代码管道,将其链接到src&一个代码构建项目,设置一些权限,完成

//serverless.yml

service: my-api
provider:
  name: aws
  runtime: python2.7

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: api/v1/message
          method: post
//buildspec.yml

version: 0.2
phases:
  install:
    commands:
      #BUILD
      - sudo apt-get update -y
  build:
    commands:
      - echo $environment
      - serverless package --stage $environment --region us-east-1
      - serverless deploy --stage $environment --region us-east-1
version: 0.1
phases:
  install:
    commands:
      #BUILD
      - zip -r lambda.zip . -x *.git*
artifacts:
  files:
    - '**/*.zip'
    - '**/*.yml'
  discard-paths: no
或者做下面的一个选择来折磨自己

您可以在代码管道中的cloudformation中执行此操作。从gatewayapi控制台中导出swagger规范并放入cloudformation模板中

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  PlayersAPI:
    Type: AWS::ApiGateway::RestApi
    Properties:
      Name: MyApi
      Description: API Description
      Body:
       "SWAGGER HERE"
将此连接到lambda有点麻烦,但我可以描述步骤。首先创建一个带有源代码、构建和部署步骤的codepipeline项目

  • src应该是github或codecommit的标准配置
  • build应该输出一个zip文件,并使用buildspec.yml之类的东西
//buildspec.yml

version: 0.2
phases:
  install:
    commands:
      #BUILD
      - sudo apt-get update -y
  build:
    commands:
      - echo $environment
      - serverless package --stage $environment --region us-east-1
      - serverless deploy --stage $environment --region us-east-1
version: 0.1
phases:
  install:
    commands:
      #BUILD
      - zip -r lambda.zip . -x *.git*
artifacts:
  files:
    - '**/*.zip'
    - '**/*.yml'
  discard-paths: no
让构建步骤导出工件MyAppBuild(或任何您想称之为MyAppBuild的东西)

最后一个管道步骤是通过控制台(其可重用)将此repo中的lambda函数创建为独立函数:

此lambda函数下载管道工件/压缩lambda函数,并使用boto对其进行更新

在这些步骤之后,您可以添加另一个步骤作为cloudformation部署步骤。将其连接到刚刚部署的lambda函数

如果要处理多个环境,可以为每个环境创建lambda函数和gatewayapi cloudformation模板,然后依次运行它们

  • 第一阶段:src
  • 第2阶段:构建
  • 阶段3:部署lambda测试,部署网关api云形成测试
  • 阶段4:验证测试
  • 第5阶段:部署lambda prod,部署网关api cloudformation prod
像这样直接使用AWS服务器也可以。但是,您需要为uri使用标准工件位置。API的定义URI:可以是从gatewayapi控制台导出的炫耀

//cloudformation.yml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  MySimpleFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: app.lambda_handler
      Runtime: python2.7
      CodeUri: s3://somebucket/somezip.zip
  MyAPI:
     Type: AWS::Serverless::Api
     Properties:
        StageName: prod
        DefinitionUri: s3://somebucket/somezip.zip

亲爱的布鲁斯。谢谢那一刻我放弃了。我没时间了。我发现Amazon解决方案的启动和运行极其复杂。我不明白亚马逊为什么不提供即插即用解决方案:-)我确实检查并验证了这一点,但这是一个相当复杂的解决方案。真正的问题在于cloudformation中的类型:“AWS::Serverless::Function”需要外部S3URI。如果您能够在模板中指定本地输入工件,那么在codepipeline中将非常简单和简单。再次感谢。只是说。。。我的同事在几小时内就在Azure上进行了连续部署。亲爱的Bruce。谢谢那一刻我放弃了。我没时间了。我发现Amazon解决方案的启动和运行极其复杂。我不明白亚马逊为什么不提供即插即用解决方案:-)我确实通过了验证