来自无服务器框架的日志未显示在 AWS CloudWatch 上
Logs from Serverless framework is not showing on AWS CloudWatch
我正在使用无服务器框架、AWS CodeCommit、CodeBuild 和 CodePipeline。当我推送我的代码并且 CodeBuild 开始部署它时,我没有从 CloudWatch 日志组内的无服务器框架获得任何反馈或日志。
我正在使用 CodeBuild 和 CodePipeline 的默认服务角色,它们是在我第一次创建新的 PipeLine 和 CodeBuild 时由 AWS 创建的。这两个角色都包含 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"
]
},
代码管道
"Action": [
"elasticbeanstalk:*",
"ec2:*",
"elasticloadbalancing:*",
"autoscaling:*",
"cloudwatch:*",
"s3:*",
"sns:*",
"cloudformation:*",
"rds:*",
"sqs:*",
"ecs:*"
],
"Resource": "*",
"Effect": "Allow"
},
这是 CloudWatch 日志组的输出。如您所见,我在部署代码中写了一些垃圾,以便从 Serverless 返回错误或失败响应,但我什么也没有得到,只有空行。
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
sls deploy -v
只会输出版本信息并退出。这是一场贪婪的比赛。
将 -v
标志更改为 --verbose
,这将起作用。
示例:
➜ 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
我正在使用无服务器框架、AWS CodeCommit、CodeBuild 和 CodePipeline。当我推送我的代码并且 CodeBuild 开始部署它时,我没有从 CloudWatch 日志组内的无服务器框架获得任何反馈或日志。
我正在使用 CodeBuild 和 CodePipeline 的默认服务角色,它们是在我第一次创建新的 PipeLine 和 CodeBuild 时由 AWS 创建的。这两个角色都包含 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"
]
},
代码管道
"Action": [
"elasticbeanstalk:*",
"ec2:*",
"elasticloadbalancing:*",
"autoscaling:*",
"cloudwatch:*",
"s3:*",
"sns:*",
"cloudformation:*",
"rds:*",
"sqs:*",
"ecs:*"
],
"Resource": "*",
"Effect": "Allow"
},
这是 CloudWatch 日志组的输出。如您所见,我在部署代码中写了一些垃圾,以便从 Serverless 返回错误或失败响应,但我什么也没有得到,只有空行。
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
sls deploy -v
只会输出版本信息并退出。这是一场贪婪的比赛。
将 -v
标志更改为 --verbose
,这将起作用。
示例:
➜ 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