aws-lambda - 导入 DynamoDB 表 - YML

标签 aws-lambda amazon-dynamodb aws-cloudformation serverless-framework

我有一个用于 AWS 节点项目的无服务器 yml 文件。我还在另一个文件中有一个 dynamodb 表。我可以毫无问题地部署项目,但是 VSCode 在我的导入行中显示红色警报问题:预期类型不正确...

无服务器.yml

service: auction-service

plugins:
  - serverless-bundle
  - serverless-pseudo-parameters

provider:
  name: aws
  runtime: nodejs12.x
  memorySize: 256
  stage: ${opt:stage, 'dev'}
  region: eu-west-1
  environment:
    AUCTIONS_TABLE_NAME: ${self:custom.AuctionsTable.name}
  iam:
    role:
      statements:
        - ${file(iam/AuctionsTableIAM.yml):AuctionsTableIAM}

resources:
  Resources:
    AuctionsTable: ${file(resources/AuctionsTable.yml):AuctionsTable}

functions:
  createAuction:
    handler: src/handlers/createAuction.handler
    events:
      - http:
          method: POST
          path: /auction

custom:
  AuctionsTable:
    name: !Ref AuctionsTable
    arn: !GetAtt AuctionsTable.Arn
  bundle:
    linting: false

拍卖表.yml:

[![AuctionsTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: AuctionsTable--${self:provider.stage}
    BillingMode: PAY_PER_REQUEST
    AttributeDefinitions:
      - AttributeName: id
        AttributeType: S
    KeySchema:
      - AttributeName: id
        KeyType: HASH][1]][1]

Error capture Error Capture

最佳答案

试试这个

resources:
  Resources:
    - ${file(resources/AuctionsTable.yml):AuctionsTable}

请注意,您需要将名称 AuctionsTable 添加到导入的文件中。

关于aws-lambda - 导入 DynamoDB 表 - YML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71671365/

相关文章:

javascript - 查询特定的GET字段?

amazon-web-services - 无法从 AWS StepFunctions 正确插入 DynamoDB 项目

amazon-web-services - 如何在 SAM 模板中设置 AWS 堆栈名称(针对 Lambda 层)?

amazon-web-services - CloudFormation 模板中不同 AWS Lambda 别名的环境变量配置

node.js - 查找未设置 DynamoDB 属性*或*大于 x 的项目

node.js - 找不到模块 'puppeteer'

amazon-dynamodb - 在 dynamodb 中将属性值更新为空白 ("")

amazon-web-services - CloudFormation - 根据 vpc 标签值动态地将安全组分配给 vpc

node.js - 如何使用带有 node.js 的 aws Lambda 将项目放入 aws DynamoDb

java - 一个 Spring Boot 应用程序中应该只存在一个 Spring Cloud Function 吗?