amazon-web-services - 如何使用AWS CDK添加S3 BucketPolicy?

标签 amazon-web-services amazon-s3 aws-cloudformation amazon-iam aws-cdk

我想将这个 CloudFormation 片段翻译成 CDK:

Type: AWS::S3::BucketPolicy
Properties:
  Bucket:
    Ref: S3BucketImageUploadBuffer
  PolicyDocument:
    Version: "2012-10-17"
    Statement:
      Action:
        - s3:PutObject
        - s3:PutObjectAcl
      Effect: Allow
      Resource:
        - ...

查看documentation here ,我没有找到提供政策文件本身的方法。

最佳答案

这是来自工作 CDK 堆栈的示例:

   artifactBucket.addToResourcePolicy(
      new PolicyStatement({
        resources: [
          this.pipeline.artifactBucket.arnForObjects("*"), 
          this.pipeline.artifactBucket.bucketArn],
        ],
        actions: ["s3:List*", "s3:Get*"],
        principals: [new ArnPrincipal(this.deploymentRole.roleArn)]
      })
    );

关于amazon-web-services - 如何使用AWS CDK添加S3 BucketPolicy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60310575/

相关文章:

amazon-web-services - Terraform RDS 实例 monitoring_role_arn 不起作用

amazon-web-services - 适用于 AWS Inspector 的 AWS CloudFormation 模板是否可以添加 SNS 主题

aws-cloudformation - 如何通过电子邮件订阅过滤发布到 SNS 主题的云形成通知?

amazon-s3 - 如何解决SPA上的 "x-cache: Error from cloudfront"

amazon-web-services - 如何获取用户在CloudFormation中选择的VPC的CIDR block ?

python - 目标 WSGI 脚本 '/opt/python/current/app/application.py' 不包含 WSGI 应用程序 'application'

mysql - 从 VPS 连接到 RDS

amazon-web-services - 如何测量在 Sun Grid Engine 中完成一批作业所需的时间?

amazon-web-services - SQS 是否真的为每条消息发送多个 S3 PUT 对象记录?

amazon-web-services - 要授予访问权限,策略必须具有具有适用资源或条件的操作