Developing an AWS CDK application that establishes an alias record for a pre-existing S3 bucket within Route53

I'm curious about how to take an existing S3 bucket and set up an alias record for it using AWS CDK.

Everything seems to be going well :

const myExistingBucket = Bucket.fromBucketName(this, 'myExistingBucket', 'myExistingBucketName')

new route53.ARecord(this, 'myAliasRecord', {
  zone: myHostedZone,
  target: route53.AddressRecordTarget.fromAlias(new route53_targets.BucketWebsiteTarget(myExistingBucket))
});

But then I encounter this error: Argument of type 'IBucket' is not assignable to parameter of type 'Bucket'.

The functions fromBucketArn(), fromBucketAttributes(), and fromBucketName() all return a type of IBucket, but the BucketWebsiteTarget() function requires a type of Bucket.

So, how can I obtain a Bucket type from an existing one using AWS CDK?

Answer №1

Ultimately, my decision was to leverage CloudFront for enabling HTTPS on an S3 Bucket (considered a best practice) following the guidance from AWS CDK Static Site Example. The key point here is that the code snippet s3BucketSource accepts a parameter of type IBucket.

const myExistingBucket = Bucket.fromBucketName(this, 'myExistingBucket', 'myExistingBucketName')

// Implementation of a CloudFront distribution providing HTTPS
const devDistribution = new cloudfront.CloudFrontWebDistribution(this, 'mySiteDistribution', {
  aliasConfiguration: {
    acmCertRef: certArn, // Required to be in us-east-1 region.
    names: ['app.example.com'],
    sslMethod: cloudfront.SSLMethod.SNI,
    securityPolicy: cloudfront.SecurityPolicyProtocol.TLS_V1_1_2016,
  },
  originConfigs: [
    {
      s3OriginSource: {
        s3BucketSource: myExistingBucket
      },
      behaviors: [{ isDefaultBehavior: true }],
    }
  ]
});

new route53.ARecord(this, 'myAliasRecord', {
  zone: zone,
  target: route53.AddressRecordTarget.fromAlias(new route53_targets.CloudFrontTarget(devDistribution)),
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Python to create and delete a subdirectory path in Amazon S3 with the help of boto3

I am facing an issue with deleting data from my S3 bucket using Python code. Here is the scenario: s3://edl-landing/lu/hello2/ Within this path, there are two tables structured like this: https://i.sstatic.net/KhX1N.png Both of these tables contain dat ...

Removing the input box from a react-select dropdown

Looking for: I need a horizontal list of tabs on the top of my application with a small ellipsis at the right end. When the ellipsis is clicked, a dropdown list of the tabs should be displayed. This way, even if there are 50 tabs, the user can easily navig ...

Passing data between components that are not actively being called can be achieved in Angular 8 by using services

I am new to Angular and I have discovered a method for passing data between components in Angular using @Input: In the parent component: ... <app-child [childMessage]="parentMessage"></app-child> ... In the child component: ... @Input() chi ...

Ways to retrieve specific Observable elements?

Having a function like this: getCategories(): Observable<any> { return this.category.find({where: {clientId: this.userApi.getCurrentId()}}) }; The return type of this.category.find is Observable<T[]>. When I invoke g ...

Ways to retrieve a URL from the assets folder

I need to establish a baseUrl for my backend requests within the assets folder. For this, I have created a server configuration file named config.json { "backendServer": { "protocol": "http", "host": " ...

FInding the inner value of a Vuetify chip

I have a Vue application that utilizes Vuetify chips to display information. I'm trying to log the value inside a specific chip when it is clicked, but I keep getting an undefined error when trying to access the array where the information comes from. ...

Adding styles to specific child nodes within a p-tree component in PrimeNG

Starting off with a demonstration example: Check out this StackBlitz for primeng p-tree. I am utilizing primeng to construct a structure for polls and answers using p-tree. The hierarchy is as follows: Participants --> Polls --> Questions --& ...

Index.js is dynamically importing a .tsx file post-build, with a specific focus on Windows

While working on my project, I decided to customize a module by cloning it and making some changes. After installing the dependencies and building it, I encountered an error when trying to run it. The error message stated: Error: Unable to resolve module & ...

After integrating session store into my application, nestjs-sequelize is not synchronizing with any models

I'm currently working on developing a Discord bot along with a website dashboard to complement it. Everything is running smoothly, except for the backend Nestjs API that I am in the process of creating. I decided to use Sequelize as the database for m ...

Angular2: Validating routes with integer parameters

Take this router as an example: { path: '/client', component: ClientRootComponent, children: [ {path: '', component: ClientListComponent}, {path: ':clientId', component: ClientOpenComponent, resolv ...

What could be causing the CSS loader in webpack to malfunction?

I am currently working on implementing the toy example mentioned in the css-loader documentation which can be found at https://github.com/webpack-contrib/css-loader Additionally, I have also followed a basic guide that recommends similar steps: https://cs ...

What is the best way to set up an endpoint in Angular for image uploading?

Using the Kolkov Angular editor in my Angular application, I have successfully created a rich text editor. Currently, I am looking to upload images from the editor to the server. I already have a function in place that takes a file as an argument and send ...

Can you explain the functionality of this Observable in the context of this Angular 2 example?

I'm not too familiar with JavaScript/TypeScript and I have a question about how this code snippet works: onGet() { this.serverService.getServers() .subscribe( (servers: any[]) => this.servers = servers, // an array of anythin ...

Initialize the routed component following the retrieval of data in the main component

In my simple Angular app, each routed component relies on data fetched from an API right after the application loads. I decided that the best approach is to initiate fetching in the root component, which also contains the router outlet. However, the activa ...

What is the recommended default value for a file in useState when working with React and TypeScript?

Can anyone help me with initializing a file using useState in React Typescript? const [images, setImages] = useState<File>(); const [formData, setFormData] = useState({ image: File }); I'm facing an issue where the file is sho ...

Filtering data in TypeScript from a different component with the filter function

Currently, I am in the process of creating a filter function for a table. The table header and table body are separate components - with one responsible for filtering the data and the other for displaying it. User input is stored in the Table Header Compo ...

What is the best way to create a dynamic URL linking to an external site in Angular 5?

When attempting to create a link like this: <a [href]="getUrl()">click me</a> getUrl() { return this.domSanitizer.bypassSecurityTrustUrl('http://sampleUrl.com'); } The link is not clickable. When hovering over the ...

Execute a specialized function with imported modules and specified parameters

Within an npm project, I am looking to execute a custom function with arguments, or ideally provide it as a script in the package.json file like this: npm run custom-function "Hello, World". Currently, I have a file called src/myFunction.ts: import * as e ...

Retrieve the attributes of a class beyond the mqtt callback limitation

Currently, I am utilizing npm-mqtt to retrieve information from a different mqtt broker. My objective is to add the obtained data to the array property of a specific class/component every time a message is received. However, I'm facing an issue wher ...

The debounced function in a React component not triggering as expected

I am facing an issue with the following React component. Even though the raiseCriteriaChange method is being called, it seems that the line this.props.onCriteriaChange(this.state.criteria) is never reached. Do you have any insights into why this.props.onC ...