我试图删除我在AWS API Gateway上手动创建的测试GET资源,但它删除了相同资源路径中的POST,现在当我sls deploy该lambda资源时,该资源不会回到API Gateway的资源列表中:
functions:
updateLibrary:
environment:
...
handler: updates/lambda.handler
events:
- http:
path: library/updated
method: post
private: true缺少library/updated POST资源?

使用library/updated POST资源的开发阶段的旧部署是什么样子:

sls deploy日志的结果:
Serverless: Stack update finished...
Serverless: Invoke aws:info
Serverless: [AWS cloudformation 200 0.484s 0 retries] describeStacks({ StackName: '***********-********-***' })
Serverless: [AWS cloudformation 200 0.508s 0 retries] listStackResources({ StackName: '***********-********-***' })
Service Information
service: ***********-********
stage: dev
region: **-****-*
stack: ***********-********-***
resources: 26
api keys:
None
endpoints:
POST - https://**********.execute-api.**-****-*.amazonaws.com/dev/library/updated
POST - https://**********.execute-api.**-****-*.amazonaws.com/dev/merge/approved
functions:
updateLibrary: ***********-********-***-updateLibrary
mergePR: ***********-********-***-mergePR
layers:
None
Serverless: [AWS sts 200 0.452s 0 retries] getCallerIdentity({})
Serverless: [AWS apigateway 200 0.633s 0 retries] getRestApis({ position: undefined, limit: 500 })
Serverless: [AWS apigateway 200 0.404s 0 retries] getStage({ restApiId: '**********', stageName: 'dev' })
Serverless: [AWS apigateway 200 0.577s 0 retries] updateStage({ restApiId: '**********',
stageName: 'dev',
patchOperations:
[ { op: 'replace',
path: '/accessLogSettings/destinationArn',
value: 'arn:aws:logs:**-****-*:**************:log-group:/aws/api-gateway/***********-********-***' },
{ op: 'replace',
path: '/accessLogSettings/format',
value: '{"requestTime":"$context.requestTime","requestId":"$context.requestId","apiId":"$context.apiId","resourceId":"$context.resourceId","resourcePath":"$context.resourcePath","path":"$context.path","httpMethod":"$context.httpMethod","status":"$context.status","authLatency":"$context.authorizer.integrationLatency","integrationLatency":"$context.integrationLatency","integrationStatus":"$context.integrationStatus","responseLatency":"$context.responseLatency","responseLength":"$context.responseLength","errorMessage":"$context.error.message","format":"SLS_ACCESS_LOG","version":"1.0.0"}' },
{ op: 'replace', path: '/*/*/logging/dataTrace', value: 'true' },
{ op: 'replace', path: '/*/*/logging/loglevel', value: 'INFO' },
[length]: 4 ] })
Serverless: Invoke aws:deploy:finalize
Serverless: [AWS s3 200 0.511s 0 retries] listObjectsV2({ Bucket: '***********-********-***-serverlessdeploymentbucket-**************',
Prefix: 'serverless/***********-********/dev' })
Serverless: Removing old service artifacts from S3...
Serverless: [AWS s3 200 0.503s 0 retries] deleteObjects({ Bucket: '***********-********-***-serverlessdeploymentbucket-**************',
Delete:
{ Objects:
[ { Key: 'serverless/***********-********/dev/******************-2020-02-09T03:31:30.226Z/***********-********.zip' },
{ Key: 'serverless/***********-********/dev/******************-2020-02-09T03:31:30.226Z/compiled-cloudformation-template.json' },
{ Key: 'serverless/***********-********/dev/******************-2020-02-09T03:31:30.226Z/custom-resources.zip' },
[length]: 3 ] } })
Serverless: Publishing service to the Serverless Dashboard...
Serverless: [AWS sts 200 0.432s 0 retries] getCallerIdentity({})
Serverless: [AWS cloudformation 200 0.49s 0 retries] describeStacks({ StackName: '***********-********-***' })
platform-sdk fetching: POST https://api.serverless.com/core/tenants/********/applications/******-*****-*******/services/***********-********/stages/dev/regions/**-****-*/deployments
Serverless: Successfully published your service to the Serverless Dashboard: https://dashboard.serverless.com/tenants/********/applications/******-*****-*******/services/***********-********/stage/dev/region/**-****-*我看到了:
patchOperations:
[ { op: 'replace'在这些日志中,可能它只是在尝试执行更新操作,而不是再次尝试创建资源,因为它认为已经存在该资源。我尝试了sls deploy --force,但同样的结果。
发布于 2020-02-09 23:58:28
这个问题是由Serverless处理、跟踪和部署您的功能和资源的方式引起的。当您删除API Gateway方法时,您实际上手动更改了应用程序的状态,它基本上是不同步的。
要解决此问题,请在serverless.yaml文件中注释掉您手动删除的整个方法,然后运行sls deploy。完成后,取消对该方法的注释,并再次部署sls。这一次,它应该再次部署您的方法。
https://stackoverflow.com/questions/60138424
复制相似问题