无服务器 API 网关资源在 aws.com 上手动删除后未返回
Serverless API Gateway Resource not coming back after manual delete on aws.com
我试图删除我在 AWS API 网关上手动创建的测试 GET
资源,但它删除了我在同一资源路径中的 POST
,现在当我sls deploy
该 lambda 资源不会返回 API 网关的资源列表:
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
但结果相同。
问题是由无服务器处理、跟踪和部署您的功能和资源的方式引起的。当您删除 API 网关方法时,您实际上手动更改了应用程序的状态,它基本上是不同步的。
要解决此问题,请在您的 serverless.yaml 文件中,注释掉您手动删除的整个方法,然后 运行 sls deploy。完成后,取消对该方法的注释并再次部署 sls。这次它应该再次部署您的方法。
我试图删除我在 AWS API 网关上手动创建的测试 GET
资源,但它删除了我在同一资源路径中的 POST
,现在当我sls deploy
该 lambda 资源不会返回 API 网关的资源列表:
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
但结果相同。
问题是由无服务器处理、跟踪和部署您的功能和资源的方式引起的。当您删除 API 网关方法时,您实际上手动更改了应用程序的状态,它基本上是不同步的。
要解决此问题,请在您的 serverless.yaml 文件中,注释掉您手动删除的整个方法,然后 运行 sls deploy。完成后,取消对该方法的注释并再次部署 sls。这次它应该再次部署您的方法。