Static website hosting feature in S3 bucket using CDK

0

I am using AWS CDK to provision an S3 bucket and host an static website. Code below was already deployed successfully by running cdk deploy command.

    const myBucket = new s3.Bucket(this, 'MyBucket', {
      bucketName: 'my-bucket-name',
      publicReadAccess: true,
      blockPublicAccess: {
        blockPublicAcls: false,
        blockPublicPolicy: false,
        ignorePublicAcls: false,
        restrictPublicBuckets: false,
      },
      removalPolicy: cdk.RemovalPolicy.DESTROY,
    });

    new s3Deploy.BucketDeployment(this, 'BucketDeploymentId', {
      sources: [s3Deploy.Source.asset("./src/website")],
      destinationBucket: myBucket,
    });

However, if I take a look to the bucket from Management Console "Static website hosting" seems to be disabled, as shown in the following screenshot

Enter image description here

Is there any missing property or configuration I need to add to make my website available?

preguntada hace 2 meses180 visualizaciones
1 Respuesta
2
Respuesta aceptada

Hello.

I think you need to add "websiteIndexDocument".
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html

The name of the index document (e.g. "index.html") for the website. Enables static website hosting for this bucket.

So I think the code should be as follows.

    const myBucket = new s3.Bucket(this, 'MyBucket', {
      bucketName: 'my-bucket-name',
      publicReadAccess: true,
      blockPublicAccess: {
        blockPublicAcls: false,
        blockPublicPolicy: false,
        ignorePublicAcls: false,
        restrictPublicBuckets: false,
      },
      removalPolicy: cdk.RemovalPolicy.DESTROY,
      websiteIndexDocument: 'index.html'
    });

    new s3Deploy.BucketDeployment(this, 'BucketDeploymentId', {
      sources: [s3Deploy.Source.asset("./src/website")],
      destinationBucket: myBucket,
    });
profile picture
EXPERTO
respondido hace 2 meses
profile picture
EXPERTO
revisado hace 5 días
profile picture
EXPERTO
revisado hace 2 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas