0

我正在尝试使用 serverless.yml 自动创建具有给定存储桶策略和 cors 配置的 s3 存储桶。下面的代码成功地创建了具有给定 cors 配置的 s3 存储桶。但是我应该如何编写存储桶策略?


custom:
  bucket: task-5-csv-uploaded

provider:
  name: aws
  runtime: nodejs14.x
  s3:
    bucketOne:
      name: ${self:custom.bucket}
      corsConfiguration:
          CorsRules:
            - AllowedMethods:
                - GET
                - PUT
              AllowedOrigins:
                - '*'
              AllowedHeaders:
                - '*'
functions:
  importFileParser:
    handler: functions/importFileParser/importFileParser.handler
    events:
      - s3: bucketOne
        event: s3:ObjectCreated:*
        rules:
          - prefix: uploaded/
          - suffix: .csv

试过这个没有成功:

provider:
  name: aws
  runtime: nodejs14.x
  s3:
    bucketOne:
      name: ${self:custom.bucket}
      corsConfiguration:
          CorsRules:
            - AllowedMethods:
                - GET
                - PUT
              AllowedOrigins:
                - '*'
              AllowedHeaders:
  iam:
    role:
      statements:
        - Effect: Allow
          Action: s3:ListBucket
          Resource:
            - arn:aws:s3:::${self:custom.bucket}

        - Effect: Allow
          Action:
            - s3:*
          Resource:
            - arn:aws:s3:::${self:custom.bucket}/*                 - '*'
plugins:
  - serverless-webpack  
4

0 回答 0