New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@rayova/cdk-cloudfront-rules

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rayova/cdk-cloudfront-rules

A rule-based CloudFront Function as a CDK Construct

latest
Source
npmnpm
Version
0.0.0
Version published
Maintainers
2
Created
Source

CDK CloudFront Rules

This CDK construct produces a CloudFront Function (not to be confused with Lambda @ Edge) that simplifies CloudFront-based URL rewriting and redirects.

Example

// Create a CloudFrontRules construct
const cloudFrontRules = new CloudFrontRules(scope, 'CloudFrontRules', {
  rules: [
    // Rewrite URIs matching /rewrite-* to /* using a capture group. (Think
    // Apache/.htaccess RewriteRule)
    Rule.rewriteRule({
      pattern: '^/rewrite-(.*)',
      location: '/$1',
    }),

    // Redirect /redirect-* to https://www.example.com/*
    Rule.rewriteRule({
      pattern: '^/redirect-(.*)',
      patternFlags: 'i', // case insensitive
      location: 'https://www.example.com/$1',
      redirectType: RedirectType.TEMPORARY,
    }),

    // Note: Rules are applied in the order they're provided. Rewrite rules
    // are applied while there has not yet been a redirect or matching
    // rewrite with the 'last' option.
    //
    // In this example, were you to visit a URI like
    // /rewrite-redirect-foobar, the first rule will rewrite you to
    // /redirect-foobar and then the second rule will match,
    // redirecting you to https://www.example.com/foobar
  ],
});

// Create your CloudFront distribution.
const distribution = new cloudfront.Distribution(scope, 'Distribution', {
  defaultBehavior: {
    origin: new cloudfront_origins.HttpOrigin('www.example.com', {
      protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
    }),

    // Associate the produced function with VIEWER_REQUEST events.
    functionAssociations: [{
      eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
      function: cloudFrontRules.function,
    }],
  },
});

Keywords

cdk

FAQs

Package last updated on 26 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts