来自无服务器框架的日志未显示在AWS CloudWatch上
我正在使用无服务器框架,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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SLS部署-v
将仅输出版本信息和退出。这是一场贪婪的比赛。将
-v
标志更改为- 冗长
,这将起作用。例子:
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: