[英]Logs from Serverless framework is not showing on AWS CloudWatch
I am using serverless framework, AWS CodeCommit, CodeBuild, and CodePipeline.我正在使用无服务器框架、AWS CodeCommit、CodeBuild 和 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.
当我推送我的代码并且 CodeBuild 开始部署它时,我没有从 CloudWatch 日志组内的无服务器框架获得任何反馈或日志。
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.我正在使用 CodeBuild 和 CodePipeline 的默认服务角色,它们是在我首次创建新的 PipeLine 和 CodeBuild 时由 AWS 创建的。 Both of those roles include polices for CloudWatch and create log groups as follows:
这两个角色都包含 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"
},
And this is the output of CloudWatch log groups.这是 CloudWatch 日志组的 output。 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.
如您所见,我在部署代码中写了一些垃圾,以便从 Serverless 返回错误或失败响应,但我什么也没有得到,只有空行。
buildspec.yml构建规范.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无服务器.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
will only output the version information and exit. sls deploy -v
只会得到 output 版本信息并退出。 It's a greedy match.这是一场贪婪的比赛。
Change the -v
flag to --verbose
and this will work.将
-v
标志更改为--verbose
,这将起作用。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.