首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无服务器框架-在S3中创建一个Lambda和S3并上传一个文件。然后,使用Lambda解压到DynamoDB

无服务器框架-在S3中创建一个Lambda和S3并上传一个文件。然后,使用Lambda解压到DynamoDB
EN

Stack Overflow用户
提问于 2020-05-14 23:40:57
回答 4查看 1.2K关注 0票数 1

这是我第一次使用无服务器框架,我的任务是用无服务器创建一个lambda、s3和dynamodb,然后调用lambda将其从s3转换到dynamo。我正在尝试获得一个由serverless生成的名称到我的S3中,以便在我的Lambda中使用它,但我没有运气。这是我的serveless.yml的样子:

代码语言:javascript
运行
复制
service: fetch-file-and-store-in-s3

frameworkVersion: ">=1.1.0"

custom:
  bucket: 
    Ref: Outputs.AttachmentsBucketName

provider:
  name: aws
  runtime: nodejs12.x
  stage: dev
  region: us-east-1
  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:PutObject
        - s3:PutObjectAcl
      Resource: "arn:aws:s3:::${self:custom.bucket.Ref}/*"

functions:
  save:
    handler: handler.save
    environment:
      BUCKET: ${self:custom.bucket.Ref}

resources:
  # S3
  AttachmentsBucket:
  Type: AWS::S3::Bucket
  Properties:
    # Set the CORS policy
    CorsConfiguration:
      CorsRules:
        -
          AllowedOrigins:
            - '*'
          AllowedHeaders:
            - '*'
          AllowedMethods:
            - GET
            - PUT
            - POST
            - DELETE
            - HEAD
          MaxAge: 3000

  # Print out the name of the bucket that is created
  Outputs:
    AttachmentsBucketName:
      Value:
        Ref: AttachmentsBucket

下面是它创建s3存储桶的部分

代码语言:javascript
运行
复制
Resources:
    # S3
    AttachmentsBucket:
      Type: AWS::S3::Bucket
      Properties:
        # Set the CORS policy
        CorsConfiguration:
          CorsRules:
            - AllowedOrigins:
                - '*'
            - AllowedHeaders:
                - '*'
            - AllowedMethods:
                - GET
                - PUT
                - POST
                - DELETE
                - HEAD
            - MaxAge: 3000
  # Print out the name of the bucket that is created
  Outputs:
    AttachmentsBucketName:
      Value:
        Ref: AttachmentsBucket

这是我目前得到的错误:

代码语言:javascript
运行
复制
λ sls deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service fetch-file-and-store-in-s3.zip file to S3 (7.32 MB)...
Serverless: Validating template...

  Error --------------------------------------------------

  Error: The CloudFormation template is invalid: Invalid template property or properties [AttachmentsBucket, Type, Properties]
EN

Stack Overflow用户

发布于 2020-05-15 03:11:52

缩进对于serverless.yml文件很重要。在本例中,AttachmentsBucket是一个资源,它应该在Resources下的子部分中有一个制表符空格,然后TypeProperties应该在资源名称:AttachmentsBucket中有一个制表符空格,而在提供的示例中实际上有两个制表符空格。CloudFormation将无法处理此特定资源,因为它无法识别具有正确名称和属性资源。

请参阅更新后的示例:

代码语言:javascript
运行
复制
Resources:
  AttachmentsBucket:
    Type: AWS::S3::Bucket
    Properties:
    # Set the CORS policy
    CorsConfiguration:
      CorsRules:
        - AllowedOrigins:
            - '*'
        - AllowedHeaders:
            - '*'
        - AllowedMethods:
            - GET
            - PUT
            - POST
            - DELETE
            - HEAD
        - MaxAge: 3000

# Print out the name of the bucket that is created
Outputs:
  AttachmentsBucketName:
    Value: !Ref AttachmentsBucket
票数 0
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61801520

复制
相关文章

相似问题

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