Serverless Framework S3 Dev/Pro Env Yaml

问题描述 投票:0回答:0

在我的无服务器框架 .yml 文件中,我正在尝试为生产和开发创建一个 S3 存储桶。我当前的 serverless.yml 看起来像这样:

  name: aws
  runtime: nodejs14.x
  region: us-east-1
  profile: default
  environment:
    BUCKET_NAME: !Ref myappBucket
  iam:
    role:
      statements:
        - Effect: "Allow"
          Action:
            - "s3:DeleteObject"
            - "s3:GetObject"
            - "s3:PutObject"
          Resource:
            Fn::Join:
              - ""
              - - "arn:aws:s3:::"
                - Ref: myappBucket
                - "/*"

resources:
  Resources:
    myappBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: myapp
        PublicAccessBlockConfiguration:
          BlockPublicAcls: true
          BlockPublicPolicy: true
          IgnorePublicAcls: true
          RestrictPublicBuckets: true

docs中,他们展示了如何设置生产和开发环境。我创建了一个开发和生产配置文件:

// config.dev.json -- the prod file looks the same but with "prod" instead of "dev"
{
  "BUCKET_NAME": "myappBucket-dev",
  "NAME": "myapp-dev"
}

在 serverless.yml 中,我然后像这样替换了

provider
代码:

provider:
  name: aws
  runtime: nodejs14.x
  region: us-east-1
  profile: default
  environment:
    BUCKET_NAME: !Ref ${file(./config.${opt:stage, 'dev'}.json):BUCKET_NAME}
  iam:
    role:
      statements:
        - Effect: "Allow"
          Action:
            - "s3:DeleteObject"
            - "s3:GetObject"
            - "s3:PutObject"
          Resource:
            Fn::Join:
              - ""
              - - "arn:aws:s3:::"
                - Ref: ${file(./config.${opt:stage, 'dev'}.json):BUCKET_NAME}
                - "/*"

但我不确定在

resource
区域做什么。如何替换密钥“myappBucket”?我尝试了一些东西,但是当我运行时我一直遇到这个错误
sls deploy --stage dev

The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [myapp-dev] in the Resources block of the template

sls deploy
命令中设置阶段标志时寻找让 .yml 文件处理 S3 的最佳方法。

amazon-s3 yaml serverless-framework
© www.soinside.com 2019 - 2024. All rights reserved.