awsroute53patterns

package
v2.137.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

CDK Construct library for higher-level Route 53 Constructs

This library provides higher-level Amazon Route 53 constructs which follow common architectural patterns.

HTTPS Redirect

If you want to speed up delivery of your web content, you can use Amazon CloudFront, the AWS content delivery network (CDN). CloudFront can deliver your entire website —including dynamic, static, streaming, and interactive content—by using a global network of edge locations. Requests for your content are automatically routed to the edge location that gives your users the lowest latency.

This construct allows creating a redirect from domainA to domainB using Amazon CloudFront and Amazon S3. You can specify multiple domains to be redirected. Learn more about routing traffic to a CloudFront web distribution.

The HttpsRedirect constructs creates:

  • Amazon CloudFront distribution - makes website available from data centres around the world
  • Amazon S3 bucket - empty bucket used for website hosting redirect (websiteRedirect) capabilities.
  • Amazon Route 53 A/AAAA Alias records - routes traffic to the CloudFront distribution
  • AWS Certificate Manager certificate - SSL/TLS certificate used by CloudFront for your domain

⚠️ The stack/construct can be used in any region for configuring an HTTPS redirect. The certificate created in Amazon Certificate Manager (ACM) will be in US East (N. Virginia) region. If you use an existing certificate, the AWS region of the certificate must be in US East (N. Virginia).

The following example creates an HTTPS redirect from foo.example.com to bar.example.com As an existing certificate is not provided, one will be created in us-east-1 by the CDK.

patterns.NewHttpsRedirect(this, jsii.String("Redirect"), &HttpsRedirectProps{
	RecordNames: []*string{
		jsii.String("foo.example.com"),
	},
	TargetDomain: jsii.String("bar.example.com"),
	Zone: route53.HostedZone_FromHostedZoneAttributes(this, jsii.String("HostedZone"), &HostedZoneAttributes{
		HostedZoneId: jsii.String("ID"),
		ZoneName: jsii.String("example.com"),
	}),
})

To have HttpsRedirect use the Certificate construct as the default created certificate instead of the deprecated DnsValidatedCertificate construct, enable the @aws-cdk/aws-route53-patters:useCertificate feature flag. If you are creating the stack in a region other than us-east-1 you must also enable crossRegionReferences on the stack.

var app app

stack := awscdk.Newstack(app, jsii.String("Stack"), &StackProps{
	CrossRegionReferences: jsii.Boolean(true),
	Env: &Environment{
		Region: jsii.String("us-east-2"),
	},
})

patterns.NewHttpsRedirect(this, jsii.String("Redirect"), &HttpsRedirectProps{
	RecordNames: []*string{
		jsii.String("foo.example.com"),
	},
	TargetDomain: jsii.String("bar.example.com"),
	Zone: route53.HostedZone_FromHostedZoneAttributes(this, jsii.String("HostedZone"), &HostedZoneAttributes{
		HostedZoneId: jsii.String("ID"),
		ZoneName: jsii.String("example.com"),
	}),
})

It is safe to upgrade to @aws-cdk/aws-route53-patterns:useCertificate since the new certificate will be created and updated on the CloudFront distribution before the old certificate is deleted.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HttpsRedirect_IsConstruct

func HttpsRedirect_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Use this method instead of `instanceof` to properly detect `Construct` instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the `constructs` library on disk are seen as independent, completely different libraries. As a consequence, the class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` the other class. `npm install` will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.

Returns: true if `x` is an object created from a class which extends `Construct`.

func NewHttpsRedirect_Override

func NewHttpsRedirect_Override(h HttpsRedirect, scope constructs.Construct, id *string, props *HttpsRedirectProps)

Types

type HttpsRedirect

type HttpsRedirect interface {
	constructs.Construct
	// The tree node.
	Node() constructs.Node
	// Returns a string representation of this construct.
	ToString() *string
}

Allows creating a domainA -> domainB redirect using CloudFront and S3.

You can specify multiple domains to be redirected.

Example:

patterns.NewHttpsRedirect(this, jsii.String("Redirect"), &HttpsRedirectProps{
	RecordNames: []*string{
		jsii.String("foo.example.com"),
	},
	TargetDomain: jsii.String("bar.example.com"),
	Zone: route53.HostedZone_FromHostedZoneAttributes(this, jsii.String("HostedZone"), &HostedZoneAttributes{
		HostedZoneId: jsii.String("ID"),
		ZoneName: jsii.String("example.com"),
	}),
})

func NewHttpsRedirect

func NewHttpsRedirect(scope constructs.Construct, id *string, props *HttpsRedirectProps) HttpsRedirect

type HttpsRedirectProps

type HttpsRedirectProps struct {
	// The redirect target fully qualified domain name (FQDN).
	//
	// An alias record
	// will be created that points to your CloudFront distribution. Root domain
	// or sub-domain can be supplied.
	TargetDomain *string `field:"required" json:"targetDomain" yaml:"targetDomain"`
	// Hosted zone of the domain which will be used to create alias record(s) from domain names in the hosted zone to the target domain.
	//
	// The hosted zone must
	// contain entries for the domain name(s) supplied through `recordNames` that
	// will redirect to the target domain.
	//
	// Domain names in the hosted zone can include a specific domain (example.com)
	// and its subdomains (acme.example.com, zenith.example.com).
	Zone awsroute53.IHostedZone `field:"required" json:"zone" yaml:"zone"`
	// The AWS Certificate Manager (ACM) certificate that will be associated with the CloudFront distribution that will be created.
	//
	// If provided, the certificate must be
	// stored in us-east-1 (N. Virginia)
	// Default: - A new certificate is created in us-east-1 (N. Virginia)
	//
	Certificate awscertificatemanager.ICertificate `field:"optional" json:"certificate" yaml:"certificate"`
	// The domain names that will redirect to `targetDomain`.
	// Default: - the domain name of the hosted zone.
	//
	RecordNames *[]*string `field:"optional" json:"recordNames" yaml:"recordNames"`
}

Properties to configure an HTTPS Redirect.

Example:

patterns.NewHttpsRedirect(this, jsii.String("Redirect"), &HttpsRedirectProps{
	RecordNames: []*string{
		jsii.String("foo.example.com"),
	},
	TargetDomain: jsii.String("bar.example.com"),
	Zone: route53.HostedZone_FromHostedZoneAttributes(this, jsii.String("HostedZone"), &HostedZoneAttributes{
		HostedZoneId: jsii.String("ID"),
		ZoneName: jsii.String("example.com"),
	}),
})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL