Serverless Framework Error: Every Resources object must contain a Type member
Serverless Framework Error: Every Resources object must contain a Type member
我正在尝试将 EFS 挂载到我的 Lambda 函数,以便我可以使用大型依赖项。到目前为止,我一直在关注 this 教程。
我稍微修改了.yml
。
serverless.yml
service: test2EFS
plugins:
- serverless-pseudo-parameters
custom:
efsAccessPoint: fsap-00**********
LocalMountPath: /mnt/efs
subnetsId: subnet-0b**********
securityGroup: sg-0b7**********
provider:
name: aws
runtime: python3.6
region: us-east-2
package:
exclude:
- node_modules/**
- .vscode/**
- .serverless/**
- .pytest_cache/**
- __pychache__/**
functions:
test:
handler: handler.handler
environment: # Service wide environment variables
MNT_DIR: ${self:custom.LocalMountPath}
vpc:
securityGroupIds:
- ${self:custom.securityGroup}
subnetIds:
- ${self:custom.subnetsId}
iamManagedPolicies:
- arn:aws:iam::aws:policy/AmazonElasticFileSystemClientReadWriteAccess
events:
- http:
path: test
method: get
resources:
extensions:
# Name of function
test2EFSLambdaFunction:
Properties:
FileSystemConfigs:
- Arn: 'arn:aws:elasticfilesystem:${self:provider.region}:#{AWS::AccountId}:access-point/${self:custom.efsAccessPoint}'
LocalMountPath: '${self:custom.LocalMountPath}'
每当我 运行 severless deploy
我得到以下错误:
Serverless: Uploading artifacts...
Serverless: Uploading service test2EFS.zip file to S3 (926 B)...
Serverless: Validating template...
Error --------------------------------------------------
Error: The CloudFormation template is invalid: Template format error: [/Resources/test2EFSLambdaFunction] Every Resources object must contain a Type member.
at provider.request.catch (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/validateTemplate.js:20:13)
at tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:725:18)
at _drainQueueStep (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:15:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:126:23)
我尝试注释掉各个部分,并将错误范围缩小到
resources:
extensions:
# Name of function
test2EFSLambdaFunction:
Properties:
FileSystemConfigs:
- Arn: 'arn:aws:elasticfilesystem:${self:provider.region}:#{AWS::AccountId}:access-point/${self:custom.efsAccessPoint}'
LocalMountPath: '${self:custom.LocalMountPath}'
除了重命名(我认为是)一个无关紧要的函数名外,此代码片段与参考相同。我尝试根据我的帐户 ID 硬编码 #{AWS::AccountId}
,但这没有用。我现在有点难过了。
通常,CloudFormation 需要资源定义中的 Type
参数,例如Type: AWS::Lambda::Function
,因此您会看到错误。在您的情况下,您正在使用 Serverless 的 Override AWS CloudFormation Resource 功能,即名称需要与 Serverless 分配的规范化函数名称完全匹配(请参阅上面链接的文档),在您的情况下,这将是 TestLambdaFunction
.
将您的代码更改为:
resources:
extensions:
TestLambdaFunction:
Properties:
[...]
我在 GitHub 上与一些人交谈过。正如 yvesonline 所述,此方法会覆盖自动生成的云形成代码。 Serverless 原生支持 EFS,推荐使用问题中描述的方法。
无服务器中的本机 EFS 看起来像这样; fileSystemConfig
存在于函数定义中:
test:
handler: handler.test
environment: # Service wide environment variables
MNT_DIR: ${self:custom.LocalMountPath}
vpc:
securityGroupIds:
- ${self:custom.securityGroup}
subnetIds:
- ${self:custom.subnetsId}
iamManagedPolicies:
- arn:aws:iam::aws:policy/AmazonElasticFileSystemClientReadWriteAccess
events:
- http:
path: test
method: get
fileSystemConfig:
localMountPath: '${self:custom.LocalMountPath}'
arn: 'arn:aws:elasticfilesystem:${self:provider.region}:#{AWS::AccountId}:access-point/${self:custom.efsAccessPoint}'
您可以阅读有关无服务器 efs 配置的更多信息here
我正在尝试将 EFS 挂载到我的 Lambda 函数,以便我可以使用大型依赖项。到目前为止,我一直在关注 this 教程。
我稍微修改了.yml
。
serverless.yml
service: test2EFS
plugins:
- serverless-pseudo-parameters
custom:
efsAccessPoint: fsap-00**********
LocalMountPath: /mnt/efs
subnetsId: subnet-0b**********
securityGroup: sg-0b7**********
provider:
name: aws
runtime: python3.6
region: us-east-2
package:
exclude:
- node_modules/**
- .vscode/**
- .serverless/**
- .pytest_cache/**
- __pychache__/**
functions:
test:
handler: handler.handler
environment: # Service wide environment variables
MNT_DIR: ${self:custom.LocalMountPath}
vpc:
securityGroupIds:
- ${self:custom.securityGroup}
subnetIds:
- ${self:custom.subnetsId}
iamManagedPolicies:
- arn:aws:iam::aws:policy/AmazonElasticFileSystemClientReadWriteAccess
events:
- http:
path: test
method: get
resources:
extensions:
# Name of function
test2EFSLambdaFunction:
Properties:
FileSystemConfigs:
- Arn: 'arn:aws:elasticfilesystem:${self:provider.region}:#{AWS::AccountId}:access-point/${self:custom.efsAccessPoint}'
LocalMountPath: '${self:custom.LocalMountPath}'
每当我 运行 severless deploy
我得到以下错误:
Serverless: Uploading artifacts...
Serverless: Uploading service test2EFS.zip file to S3 (926 B)...
Serverless: Validating template...
Error --------------------------------------------------
Error: The CloudFormation template is invalid: Template format error: [/Resources/test2EFSLambdaFunction] Every Resources object must contain a Type member.
at provider.request.catch (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/validateTemplate.js:20:13)
at tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:725:18)
at _drainQueueStep (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:15:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:126:23)
我尝试注释掉各个部分,并将错误范围缩小到
resources:
extensions:
# Name of function
test2EFSLambdaFunction:
Properties:
FileSystemConfigs:
- Arn: 'arn:aws:elasticfilesystem:${self:provider.region}:#{AWS::AccountId}:access-point/${self:custom.efsAccessPoint}'
LocalMountPath: '${self:custom.LocalMountPath}'
除了重命名(我认为是)一个无关紧要的函数名外,此代码片段与参考相同。我尝试根据我的帐户 ID 硬编码 #{AWS::AccountId}
,但这没有用。我现在有点难过了。
通常,CloudFormation 需要资源定义中的 Type
参数,例如Type: AWS::Lambda::Function
,因此您会看到错误。在您的情况下,您正在使用 Serverless 的 Override AWS CloudFormation Resource 功能,即名称需要与 Serverless 分配的规范化函数名称完全匹配(请参阅上面链接的文档),在您的情况下,这将是 TestLambdaFunction
.
将您的代码更改为:
resources:
extensions:
TestLambdaFunction:
Properties:
[...]
我在 GitHub 上与一些人交谈过。正如 yvesonline 所述,此方法会覆盖自动生成的云形成代码。 Serverless 原生支持 EFS,推荐使用问题中描述的方法。
无服务器中的本机 EFS 看起来像这样; fileSystemConfig
存在于函数定义中:
test:
handler: handler.test
environment: # Service wide environment variables
MNT_DIR: ${self:custom.LocalMountPath}
vpc:
securityGroupIds:
- ${self:custom.securityGroup}
subnetIds:
- ${self:custom.subnetsId}
iamManagedPolicies:
- arn:aws:iam::aws:policy/AmazonElasticFileSystemClientReadWriteAccess
events:
- http:
path: test
method: get
fileSystemConfig:
localMountPath: '${self:custom.LocalMountPath}'
arn: 'arn:aws:elasticfilesystem:${self:provider.region}:#{AWS::AccountId}:access-point/${self:custom.efsAccessPoint}'
您可以阅读有关无服务器 efs 配置的更多信息here