Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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 在CodeStar和CodePipeline中为AWS Lambda服务创建环境的问题_Amazon Web Services_Aws Lambda_Amazon Cloudformation_Aws Codepipeline_Aws Codestar - Fatal编程技术网

Amazon web services 在CodeStar和CodePipeline中为AWS Lambda服务创建环境的问题

Amazon web services 在CodeStar和CodePipeline中为AWS Lambda服务创建环境的问题,amazon-web-services,aws-lambda,amazon-cloudformation,aws-codepipeline,aws-codestar,Amazon Web Services,Aws Lambda,Amazon Cloudformation,Aws Codepipeline,Aws Codestar,我使用AWS CodeStar创建了一个带有“Express.js AWS Lambda Webservice”CodeStar模板的新应用程序。这很好,因为它使用AWS CodePipeline为我设置了一个简单的CI/CD管道。默认情况下,管道有3个步骤用于从git repo获取源代码、运行构建步骤,然后部署到“dev”环境 我的问题是,我无法将其设置为使我的管道具有多个环境:开发、暂存和产品。 我当前的部署步骤有2个操作:GenerateChangeSet和ExecuteChangeSet

我使用AWS CodeStar创建了一个带有“Express.js AWS Lambda Webservice”CodeStar模板的新应用程序。这很好,因为它使用AWS CodePipeline为我设置了一个简单的CI/CD管道。默认情况下,管道有3个步骤用于从git repo获取源代码、运行构建步骤,然后部署到“dev”环境

我的问题是,我无法将其设置为使我的管道具有多个环境:开发、暂存和产品。

我当前的部署步骤有2个操作:GenerateChangeSet和ExecuteChangeSet。以下是原始开发环境构建步骤中操作的配置,这些配置非常有效:

我已经在管道的末尾创建了一个新的部署阶段来部署到staging,但老实说,我不知道如何更改配置。我想最终我希望能够进入AWS控制台的AWS Lambda部分,看到三个独立的Lambda函数:binance bot dev、binance bot staging、binance-bot-prod。然后,我可以将它们中的每一个设置为cloudwatch计划事件,或者使用它们自己的api网关url公开

这是我尝试用于新部署阶段的配置:

我真的不确定这个配置是否正确,以及为了以我想要的方式部署,我应该更改什么

例如,我应该更改“堆栈名称”,还是应该将其保留为“awscodestar binance bot lambda”,或者像我现在这样为每个环境更改它

另外,我指向项目中的另一个template.yml文件。原始的template.yml如下所示:

AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
- AWS::CodeStar

Parameters:
  ProjectId:
    Type: String
    Description: AWS CodeStar projectID used to associate new resources to team members

Resources:
  Dev:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs4.3
      Environment:
        Variables:
          NODE_ENV: dev
      Role:
        Fn::ImportValue:
          !Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
      Events:
        GetEvent:
          Type: Api
          Properties:
            Path: /
            Method: get
        PostEvent:
          Type: Api
          Properties:
            Path: /
            Method: post
version: 0.2

phases:
  install:
    commands:
      # Install dependencies needed for running tests
      - npm install

      # Upgrade AWS CLI to the latest version
      - pip install --upgrade awscli
  pre_build:
    commands:
      # Discover and run unit tests in the 'tests' directory
      - npm test
  build:
    commands:
      # Use AWS SAM to package the application using AWS CloudFormation
      - aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template template-export.yml
      - aws cloudformation package --template template.staging.yml --s3-bucket $S3_BUCKET --output-template template-export.staging.yml
      - aws cloudformation package --template template.prod.yml --s3-bucket $S3_BUCKET --output-template template-export.prod.yml
artifacts:
  type: zip
  files:
    - template-export.yml
对于template.staging.yml,我使用完全相同的配置,只是在“资源”下将“Dev:”更改为“staging:”,并且还更改了NODE_ENV环境变量的值。因此,我基本上想知道这是我想要实现的正确配置吗?

假设配置中的所有内容都是正确的,那么我需要对该错误进行故障排除。如上所述设置好所有内容后,我可以运行管道,但当它进入暂存构建步骤时,GenerateCharge_暂存操作将失败,并显示以下错误消息:

操作执行失败用户: arn:aws:sts::954459734159:假定角色/CodeStarWorker二进制机器人代码管道/1524253307698 未被授权在上执行:cloudformation:DescripteBacks 资源: arn:aws:cloudformation:us-east-1:954459734159:stack/awscodestar双星机器人lambda staging/* (服务:AmazonCloudFormation;状态代码:403;错误代码: 拒绝访问;请求ID:dd801664-44d2-11e8-a2de-8fa6c42cbf86)

在这个错误消息中,我似乎需要为我的“CodeStarWorker binance bot CodePipeline”添加“cloudformation:DescribeCacks”,因此我转到IAM->Roles并单击CodeStarWorker binance bot CodePipeline角色。然而,当我点击“CodeStarWorker binance bot CodePipeline”并深入了解CloudFormation的策略信息时,看起来这个角色已经拥有了“DescribeCacks”的权限

如果有人能指出我做错了什么,或者在理解和思考如何使用AWS CodePipeline实现多个环境方面提供指导,那就太好了。谢谢

更新:

我将Deploy_To_Staging pipeline阶段中的“Stack name”改回“awscodestar binance bot lambda”。但是,我随后从GenerateChange_暂存操作中得到此错误:

操作执行失败无效的TemplatePath: binance bot BuildArtifact::template-export.staging.yml。人造物品 binance机器人构建工件不存在

更新2: 在我项目的根目录中,我有一个由CodeStar生成的buildspec.yml文件。看起来是这样的:

AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
- AWS::CodeStar

Parameters:
  ProjectId:
    Type: String
    Description: AWS CodeStar projectID used to associate new resources to team members

Resources:
  Dev:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs4.3
      Environment:
        Variables:
          NODE_ENV: dev
      Role:
        Fn::ImportValue:
          !Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
      Events:
        GetEvent:
          Type: Api
          Properties:
            Path: /
            Method: get
        PostEvent:
          Type: Api
          Properties:
            Path: /
            Method: post
version: 0.2

phases:
  install:
    commands:
      # Install dependencies needed for running tests
      - npm install

      # Upgrade AWS CLI to the latest version
      - pip install --upgrade awscli
  pre_build:
    commands:
      # Discover and run unit tests in the 'tests' directory
      - npm test
  build:
    commands:
      # Use AWS SAM to package the application using AWS CloudFormation
      - aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template template-export.yml
      - aws cloudformation package --template template.staging.yml --s3-bucket $S3_BUCKET --output-template template-export.staging.yml
      - aws cloudformation package --template template.prod.yml --s3-bucket $S3_BUCKET --output-template template-export.prod.yml
artifacts:
  type: zip
  files:
    - template-export.yml
然后我将其添加到CloudFormation部分:

然后我将其添加到“build:->commands:”部分:

我把这个添加到了“文件”:

  • 模板-export.staging.yml
  • 模板-export.prod.yml
然而,我仍然得到一个错误,即“binance bot BuildArtifact不存在”

以下是buildspec.yml更改后的完整错误:

操作执行失败无效的TemplatePath: binance bot BuildArtifact::template-export.staging.yml。人造物品 binance机器人构建工件不存在

我觉得很奇怪,我可以在管道的一个阶段而不是另一个阶段访问“binance bot BuildArtifact”。是否构建工件仅可直接用于构建阶段之后的一个管道阶段?有人能帮我访问这个“binance机器人构建工件”吗?谢谢

例如,我应该更改“堆栈名称”,还是应该将其保留为“awscodestar binance bot lambda”,或者像我现在这样为每个环境更改它

您应该为每个环境使用唯一的堆栈名称。如果您没有这样做,您将用“登台”环境替换“开发”环境,等等

所以,我基本上想知道这是我想要实现的正确配置吗

我不这么认为。您应该为每个环境使用完全相同的模板。要更改每个部署的环境名称,可以使用“参数覆盖”字段为“环境”参数选择正确的值

看起来这个角色已经有了“DescripteBacks”的权限

这里的问题可能是您的IAM角色对开发堆栈只有DescribeStacks权限吗?它似乎没有描述暂存堆栈的权限。也许您可以在策略中添加一个“通配符”/“星号”,使其与所有堆栈名称匹配

是否构建工件仅可直接用于构建阶段之后的一个管道阶段

不,那不是我的前任