如何将存储桶策略json转换为serverless.yaml

一段时间以来,我一直在使用无服务器。我一直在将图像上传到s3存储桶。我在aws控制台中手动创建了s3存储桶。现在,我正在努力通过yaml创建s3存储桶,并根据需要上传文件。

我已使用以下yaml命令通过yaml成功创建了s3存储桶:

 resources:      
  Resources:
   ProfPicBucketv4:
    Type: AWS::S3::Bucket
    Properties:
       BucketName: 'prof-pic-bucketv4'
       # Set the CORS policy
       CorsConfiguration:
         CorsRules:
           -
             AllowedOrigins:
               - '*'
             AllowedHeaders:
               - '*'
             AllowedMethods:
               - GET
               - PUT
               - POST
               - DELETE
               - HEAD

这等效于CORS配置:

如何将存储桶策略json转换为serverless.yaml

现在,当我尝试上传文件时,即使使用CORS配置,它也使我无法访问。我的下一个目标是将这张图片转换为Yaml:

如何将存储桶策略json转换为serverless.yaml

我已经有这个了

service: campproject

provider:
  name: aws
  region: us-east-1

  # Lambda runs faster if we allocate the maximum memory to each function execution...
  memorySize: 3008
  timeout: 30

  runtime: nodejs10.x

  # Prevent storing revisions in AWS - We're storing them as Docker Images instead...
  versionFunctions: false

  stage: ${opt:stage,self:custom.defaultStage}
  profile: ${self:custom.awsProfiles.${self:provider.stage}}

  iamRoleStatements:
    - Effect: "Allow"
      action:
        - "s3:ListBucket"
        - "s3:GetObject"
        - "s3:PutObject"
      Resource: "arn:aws:s3:::prof-pic-bucketv4/*"
mzpywen 回答:如何将存储桶策略json转换为serverless.yaml

这里已经回答了。

Stackoverflow link here

Resources:
  AttachmentsBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: range-picker-bucket-${self:custom.stage}

  AttachmentsBucketAllowPublicReadPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
      Bucket: !Ref AttachmentsBucket
      PolicyDocument:
        Version: "2012-10-17"
        Statement: 
          - Effect: Allow
            Action: 
              - "s3:GetObject"
            Resource: 
              - !Join ['/',[!Ref AttachmentsBucket,'public']]
            Principal: "*"
本文链接:https://www.f2er.com/3114072.html

大家都在问