首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无服务器框架错误:每个资源对象都必须包含一个类型成员

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

Stack Overflow用户
提问于 2021-02-08 09:07:28
回答 2查看 483关注 0票数 0

我正在尝试将EFS挂载到我的Lambda函数中,以便可以使用大型依赖项。到目前为止,我一直在关注this教程。

我稍微修改了一下.yml

serverless.yml

代码语言:javascript
复制
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时,我都会得到以下错误:

代码语言:javascript
复制
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)

我尝试注释出各个部分,并将错误范围缩小到内部某个位置

代码语言:javascript
复制
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}进行硬编码,但这不起作用。我现在有点迷惑了。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-02-08 19:24:12

通常情况下,CloudFormation会在资源定义中使用Type参数,例如Type: AWS::Lambda::Function,这就是为什么你会看到这个错误。在你的例子中,你使用的是无服务器的Override AWS CloudFormation Resource功能,即名称需要与无服务器分配的规范化函数名完全匹配(参见上面链接的文档),在你的例子中应该是TestLambdaFunction

将您的代码更改为:

代码语言:javascript
复制
resources:
  extensions:
    TestLambdaFunction:
      Properties:
        [...]
票数 1
EN

Stack Overflow用户

发布于 2021-02-11 02:45:42

我在GitHub上和一些人聊过。正如yvesonline所说的那样,这个方法覆盖了自动生成的云形成代码。Serverless具有对EFS的本机支持,并且推荐使用问题中描述的方法。

无服务器中的原生EFS看起来像这样;fileSystemConfig存在于函数定义中:

代码语言:javascript
复制
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的更多信息

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66094737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档