无服务器框架 AWS Codebuild 成功完成(?)但没有 APIGateway 或 lambda

时间:2021-03-04 21:09:29

标签: amazon-web-services aws-codepipeline

在此先感谢您的帮助。 我是无服务器和无服务器框架的新手。

我是第一次尝试 CI/CD 管道。 我已经在离线环境中运行了 serverless.yml,并且我在本地调试和健康的 DynamoDB 表中有功能性的 CRUD 操作。

管道是 AWS CodeCommit->CodeBuild->CodePipeLine

管道流动没有错误,但输出中没有 lambda 或 APIGateway。

我希望它是某个地方的简单开关或类似的开关?

buildspec.yml

version: 0.2

phases:
  install:
    commands:
      - echo Installing serverless...
        npm install -g serverless


  pre_build:
    commands:
      - echo Install npm source dependencies...
        npm install

  build:
    commands:
      - echo Deployment started on `date`...
        echo Deploying with the Serverless Framework...
        sls deploy -v -s $ENV_NAME

  post_build:
    commands:
      - echo Deployment completed on `date`...

无服务器.yml

service: sls-notes-backend
frameworkVersion: '2'

plugins:
  -
    serverless-offline

custom:
  allowedHeaders:
    - Accpet
    - Content-Type
    - Content-Length
    - Authorization
    - X-Amz-Date
    - X-Api-Key
    - X-Amz-Security-Token
    - X-Amz-User-Agent
    - app_user_id
    - app_user_name

provider:
  name: aws
  runtime: nodejs12.x
  lambdaHashingVersion: 20201221
  region: us-east-1
  stage: prod
  memorySize: 128
  timeout: 5
  endpointType: regional
  environment:
    NOTES_TABLE: ${self:service}-${opt:stage, self:provider.stage}
  iamRoleStatements:
    -
      Effect: Allow
      Action:
        - dynamodb:Query
        - dynamodb:PutItem
        - dynamodb:DeletItem
      Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.NOTES_TABLE}"

functions:
  add-note:
    handler: api/add-note.handler
    description: POST /note
    events:
      -
        http:
          path: note
          method: post
          cors:
            origin: '*'
            headers:  ${self:custom.allowedHeaders}
  update-note:
    handler: api/update-note.handler
    description: PATCH /note
    events:
      -
        http:
          path: note
          method: patch
          cors:
            origin: '*'
            headers:  ${self:custom.allowedHeaders}
  get-notes:
    handler: api/get-notes.handler
    description: GET /note
    events:
      -
        http:
          path: notes
          method: get
          cors:
            origin: '*'
            headers:  ${self:custom.allowedHeaders}
  get-note:
    handler: api/get-note.handler
    description: GET /note/n/{note_id}
    events:
      -
        http:
          path: note/n/{note_id}
          method: get
          cors:
            origin: '*'
            headers:  ${self:custom.allowedHeaders}
  delete-note:
    handler: api/delete-note.handler
    description: DELETE /note
    events:
      -
        http:
          path: note/t/{timestamp}
          method: delete
          cors:
            origin: '*'
            headers:  ${self:custom.allowedHeaders}

resources:
  Resources:
    NotesTable:
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      Properties:
        TableName: ${self:provider.environment.NOTES_TABLE}
        AttributeDefinitions:
          -
            AttributeName: user_id
            AttributeType: S

          -
            AttributeName: timestamp
            AttributeType: N

          -
            AttributeName: note_id
            AttributeType: S

        KeySchema:
          -
            AttributeName: user_id
            KeyType: HASH

          -
            AttributeName: timestamp
            KeyType: RANGE

        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        GlobalSecondaryIndexes:
          - IndexName: note_id-index
            KeySchema:
              -
                AttributeName: note_id
                KeyType: HASH
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1

代码构建日志:

[Container] 2021/03/06 07:51:03 Waiting for agent ping
[Container] 2021/03/06 07:51:05 Waiting for DOWNLOAD_SOURCE
[Container] 2021/03/06 07:51:06 Phase is DOWNLOAD_SOURCE
[Container] 2021/03/06 07:51:06 CODEBUILD_SRC_DIR=/codebuild/output/src664645733/src
[Container] 2021/03/06 07:51:06 YAML location is /codebuild/output/src664645733/src/buildspec.yml
[Container] 2021/03/06 07:51:06 Processing environment variables
[Container] 2021/03/06 07:51:06 No runtime version selected in buildspec.
[Container] 2021/03/06 07:51:06 Moving to directory /codebuild/output/src664645733/src
[Container] 2021/03/06 07:51:06 Registering with agent
[Container] 2021/03/06 07:51:06 Phases found in YAML: 4
[Container] 2021/03/06 07:51:06  INSTALL: 1 commands
[Container] 2021/03/06 07:51:06  PRE_BUILD: 1 commands
[Container] 2021/03/06 07:51:06  BUILD: 1 commands
[Container] 2021/03/06 07:51:06  POST_BUILD: 1 commands
[Container] 2021/03/06 07:51:06 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2021/03/06 07:51:06 Phase context status code:  Message: 
[Container] 2021/03/06 07:51:06 Entering phase INSTALL
[Container] 2021/03/06 07:51:06 Running command echo Installing serverless... npm install -g serverless
Installing serverless... npm install -g serverless

[Container] 2021/03/06 07:51:06 Phase complete: INSTALL State: SUCCEEDED
[Container] 2021/03/06 07:51:06 Phase context status code:  Message: 
[Container] 2021/03/06 07:51:06 Entering phase PRE_BUILD
[Container] 2021/03/06 07:51:06 Running command echo Install npm source dependencies... npm install
Install npm source dependencies... npm install

[Container] 2021/03/06 07:51:06 Phase complete: PRE_BUILD State: SUCCEEDED
[Container] 2021/03/06 07:51:06 Phase context status code:  Message: 
[Container] 2021/03/06 07:51:06 Entering phase BUILD
[Container] 2021/03/06 07:51:06 Running command echo Deployment started on `date`... echo Deploying with the Serverless Framework... sls deploy -v -s $ENV_NAME
Deployment started on Sat Mar 6 07:51:06 UTC 2021... echo Deploying with the Serverless Framework... sls deploy -v -s prod

[Container] 2021/03/06 07:51:06 Phase complete: BUILD State: SUCCEEDED
[Container] 2021/03/06 07:51:06 Phase context status code:  Message: 
[Container] 2021/03/06 07:51:06 Entering phase POST_BUILD
[Container] 2021/03/06 07:51:06 Running command echo Deployment completed on `date`...
Deployment completed on Sat Mar 6 07:51:06 UTC 2021...

[Container] 2021/03/06 07:51:06 Phase complete: POST_BUILD State: SUCCEEDED
[Container] 2021/03/06 07:51:06 Phase context status code:  Message: 

1 个答案:

答案 0 :(得分:0)

我想我应该有点尴尬,因为在错误开始出现后,我更仔细地查看了 yml 规范,发现早期提到的那些滴答 hephalump 非常重要,因为没有一个 yml 继续执行上一个的 echo 命令行表示整个 Buildspec 将自身缩减为一个大字符串。我已将 Buildspec.yml 发布到功能版本中,供任何人将来参考。

感谢 Hephalump 提供了正确的 Buildspec.yml

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - echo Installing serverless...
      - npm install -g serverless
  pre_build:
    commands:
      - echo Install npm source dependencies...
      - npm install

  build:
    commands:
      - echo Deployment started on `date`...
      - echo Deploying with the Serverless Framework...
      - sls deploy -v -s $ENV_NAME
  post_build:
    commands:
      - echo Deployment completed on `date`...
相关问题