Aws lambda 无服务器框架错误:每个资源对象必须包含一个类型成员

Aws lambda 无服务器框架错误:每个资源对象必须包含一个类型成员,aws-lambda,serverless-framework,amazon-efs,Aws Lambda,Serverless Framework,Amazon Efs,我正在尝试将EFS装载到Lambda函数中,以便使用大型依赖项。到目前为止,我一直在遵循教程 我稍微修改了.yml serverless.yml 每当我运行severless deploy时,都会出现以下错误: Serverless: Uploading artifacts... Serverless: Uploading service test2EFS.zip file to S3 (926 B)... Serverless: Validating template... Error

我正在尝试将EFS装载到Lambda函数中,以便使用大型依赖项。到目前为止,我一直在遵循教程

我稍微修改了
.yml

serverless.yml 每当我运行
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在资源定义中需要一个
类型
参数,例如
类型:AWS::Lambda::Function
,因此您会看到错误。在您的情况下,您使用的是Serverless的功能,即名称需要与Serverless分配的规范化函数名称完全匹配(请参阅上面链接的文档),在您的情况下,这将是
testlambdfunction

将代码更改为:

resources:
  extensions:
    TestLambdaFunction:
      Properties:
        [...]

我在GitHub上和一些人谈过。如yvesonline所述,该方法覆盖自动生成的云形成代码。Serverless本机支持EFS,建议使用问题中描述的方法

serverless中的本机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配置的信息

,您就是这样做的人。谢谢
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}'