来自无服务器框架的日志未显示在AWS CloudWatch上

发布于 2025-01-26 15:11:29 字数 3183 浏览 4 评论 0原文

我正在使用无服务器框架,AWS CodeCommit,CodeBuild和Codepipeline。当我推动代码和CodeBuild开始部署它时,我不会从CloudWatch日志组中的无服务器框架中获得任何反馈或日志。

我正在使用默认的服务角色作为CodeBuild和Codepipeline,这些角色是AWS创建的,当时我首次创建了新的管道和CodeBuild。这两个角色都包括CloudWatch的策略,并创建日志组,如下所示:

codebuild

"Statement": [
    {
        "Effect": "Allow",
        "Resource": [
            "arn:aws:logs:us-west-2:*****:log-group:/aws/codebuild/sis-notes-backend-codebuild",
            "arn:aws:logs:us-west-2:*****:log-group:/aws/codebuild/sis-notes-backend-codebuild:*"
        ],
        "Action": [
            "logs:CreateLogGroup",
            "logs:CreateLogStream",
            "logs:PutLogEvents"
        ]
   },

codepipeline

"Action": [
            "elasticbeanstalk:*",
            "ec2:*",
            "elasticloadbalancing:*",
            "autoscaling:*",
            "cloudwatch:*",
            "s3:*",
            "sns:*",
            "cloudformation:*",
            "rds:*",
            "sqs:*",
            "ecs:*"
        ],
        "Resource": "*",
        "Effect": "Allow"
    },

,这是CloudWatch日志组的输出。如您所见,我已经在部署代码中写了垃圾以获取错误或从无服务器中回响应失败,但我没有什么只有空的行。

buildspec.yml

version: 0.2

phases:
  install:
    commands:
      - echo Installing Serverless
      - npm install -g serverless
  pre_build:
    commands:
      - echo Install source NPM dependencies
      - npm install
  build:
    commands:
      - echo Deployment started on `date`
      - echo Deploying with the Serverless Framework
      - sls deploy -v -s $ENV_NAMEss kklksadk
  post_build:
    commands:
      - echo Deployment completed on `date`

serverless.yml

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

provider:
  name: aws
  runtime: nodejs14.x
  region: us-west-2
  stage: prod
  memorySize: 128
  timeout: 4
  endpointType: regional
  environment:
    NOTES_TABLE: ${self:service}-${opt:stage, self:provider.stage}

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: 2
              WriteCapacityUnits: 2

I am using serverless framework, AWS CodeCommit, CodeBuild, and CodePipeline. When I push my code and CodeBuild starts to deploy it, I don't get any feedback or logs from serverless framework inside the CloudWatch log groups.

I am using the default service roles for CodeBuild and CodePipeline which are created by AWS when I first created a new PipeLine and CodeBuild. Both of those roles include polices for CloudWatch and create log groups as follows:

CodeBuild

"Statement": [
    {
        "Effect": "Allow",
        "Resource": [
            "arn:aws:logs:us-west-2:*****:log-group:/aws/codebuild/sis-notes-backend-codebuild",
            "arn:aws:logs:us-west-2:*****:log-group:/aws/codebuild/sis-notes-backend-codebuild:*"
        ],
        "Action": [
            "logs:CreateLogGroup",
            "logs:CreateLogStream",
            "logs:PutLogEvents"
        ]
   },

CodePipeline

"Action": [
            "elasticbeanstalk:*",
            "ec2:*",
            "elasticloadbalancing:*",
            "autoscaling:*",
            "cloudwatch:*",
            "s3:*",
            "sns:*",
            "cloudformation:*",
            "rds:*",
            "sqs:*",
            "ecs:*"
        ],
        "Resource": "*",
        "Effect": "Allow"
    },

And this is the output of CloudWatch log groups. As you can see that I've wrote rubbish in the deploy code in order to get an error or failed response back from Serverless, but I got nothing just empty lines.

CloudWatch

buildspec.yml

version: 0.2

phases:
  install:
    commands:
      - echo Installing Serverless
      - npm install -g serverless
  pre_build:
    commands:
      - echo Install source NPM dependencies
      - npm install
  build:
    commands:
      - echo Deployment started on `date`
      - echo Deploying with the Serverless Framework
      - sls deploy -v -s $ENV_NAMEss kklksadk
  post_build:
    commands:
      - echo Deployment completed on `date`

serverless.yml

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

provider:
  name: aws
  runtime: nodejs14.x
  region: us-west-2
  stage: prod
  memorySize: 128
  timeout: 4
  endpointType: regional
  environment:
    NOTES_TABLE: ${self:service}-${opt:stage, self:provider.stage}

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: 2
              WriteCapacityUnits: 2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长安忆 2025-02-02 15:11:29

SLS部署-v将仅输出版本信息和退出。这是一场贪婪的比赛。

-v标志更改为- 冗长,这将起作用。

例子:

➜  js-library-test sls deploy -v
Running "serverless" from node_modules
Framework Core: 3.1.1 (local) 3.12.0v (global)
Plugin: 6.0.0
SDK: 4.3.1

➜  js-library-test

sls deploy -v will only output the version information and exit. It's a greedy match.

Change the -v flag to --verbose and this will work.

Example:

➜  js-library-test sls deploy -v
Running "serverless" from node_modules
Framework Core: 3.1.1 (local) 3.12.0v (global)
Plugin: 6.0.0
SDK: 4.3.1

➜  js-library-test
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文