Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
¿Cómo agregar S3 BucketPolicy con AWS CDK?

Quiero traducir esta pieza de CloudFormation a CDK:

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

Mirando la documentación aquí , no veo una manera de proporcionar el documento de política en sí.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Este es un ejemplo de un CDK-Stack en funcionamiento:

 artifactBucket.addToResourcePolicy( new PolicyStatement({ resources: [ this.pipeline.artifactBucket.arnForObjects("*"), this.pipeline.artifactBucket.bucketArn], ], actions: ["s3:List*", "s3:Get*"], principals: [new ArnPrincipal(this.deploymentRole.roleArn)] }) );
over 4 years ago · Santiago Trujillo Report

0

Sobre la base de la respuesta de @Thomas Wagner, así es como lo hice. Estaba tratando de limitar el depósito a un rango de IP determinado:

 import * as cdk from '@aws-cdk/core'; import * as s3 from '@aws-cdk/aws-s3'; import * as s3Deployment from '@aws-cdk/aws-s3-deployment'; import * as iam from '@aws-cdk/aws-iam'; export class StaticSiteStack extends cdk.Stack { constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); // Bucket where frontend site goes. const mySiteBucket = new s3.Bucket(this, 'mySiteBucket', { websiteIndexDocument: "index.html" }); let ipLimitPolicy = new iam.PolicyStatement({ actions: ['s3:Get*', 's3:List*'], resources: [mySiteBucket.arnForObjects('*')], principals: [new iam.AnyPrincipal()] }); ipLimitPolicy.addCondition('IpAddress', { "aws:SourceIp": ['1.2.3.4/22'] }); // Allow connections from my CIDR mySiteBucket.addToResourcePolicy(ipLimitPolicy); // Deploy assets const mySiteDeploy = new s3Deployment.BucketDeployment(this, 'deployAdminSite', { sources: [s3Deployment.Source.asset("./mysite")], destinationBucket: mySiteBucket }); } }

Pude usar las funciones auxiliares s3.arnForObjects() e iam.AnyPrincipal() en lugar de especificar ARN o principales directamente.

Los activos que quiero implementar en el depósito se mantienen en la raíz del directorio de mi proyecto en un directorio llamado mysite y luego se hace referencia a través de una llamada a s3Deployment.BucketDeployment . Este puede ser cualquier directorio al que tenga acceso su proceso de compilación, por supuesto.

over 4 years ago · Santiago Trujillo Report

0

El CDK hace esto un poco diferente. Creo que se supone que debes usar bucket.addToResourcePolicy , como se documenta aquí .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!