Socket
Socket
Sign inDemoInstall

@aws-sdk/client-cloudfront

Package Overview
Dependencies
Maintainers
5
Versions
409
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-sdk/client-cloudfront

AWS SDK for JavaScript Cloudfront Client for Node.js, Browser and React Native


Version published
Weekly downloads
384K
decreased by-1.9%
Maintainers
5
Weekly downloads
 
Created

What is @aws-sdk/client-cloudfront?

@aws-sdk/client-cloudfront is a part of the AWS SDK for JavaScript, which allows developers to interact with Amazon CloudFront, a content delivery network (CDN) service. This package provides a variety of functionalities to manage CloudFront distributions, invalidations, and other related resources.

What are @aws-sdk/client-cloudfront's main functionalities?

Create CloudFront Distribution

This feature allows you to create a new CloudFront distribution. The code sample demonstrates how to set up a distribution with a custom origin and default cache behavior.

const { CloudFrontClient, CreateDistributionCommand } = require('@aws-sdk/client-cloudfront');

const client = new CloudFrontClient({ region: 'us-east-1' });

const params = {
  DistributionConfig: {
    CallerReference: 'unique-string',
    Origins: {
      Quantity: 1,
      Items: [
        {
          Id: 'origin-1',
          DomainName: 'example.com',
          CustomOriginConfig: {
            HTTPPort: 80,
            HTTPSPort: 443,
            OriginProtocolPolicy: 'http-only'
          }
        }
      ]
    },
    DefaultCacheBehavior: {
      TargetOriginId: 'origin-1',
      ViewerProtocolPolicy: 'allow-all',
      ForwardedValues: {
        QueryString: false,
        Cookies: {
          Forward: 'none'
        }
      },
      TrustedSigners: {
        Enabled: false,
        Quantity: 0
      }
    },
    Enabled: true
  }
};

const run = async () => {
  try {
    const data = await client.send(new CreateDistributionCommand(params));
    console.log('Distribution created:', data);
  } catch (err) {
    console.error('Error creating distribution:', err);
  }
};

run();

List CloudFront Distributions

This feature allows you to list all CloudFront distributions in your AWS account. The code sample demonstrates how to retrieve and log the list of distributions.

const { CloudFrontClient, ListDistributionsCommand } = require('@aws-sdk/client-cloudfront');

const client = new CloudFrontClient({ region: 'us-east-1' });

const run = async () => {
  try {
    const data = await client.send(new ListDistributionsCommand({}));
    console.log('Distributions:', data.DistributionList.Items);
  } catch (err) {
    console.error('Error listing distributions:', err);
  }
};

run();

Create Invalidation

This feature allows you to create an invalidation for a CloudFront distribution. The code sample demonstrates how to invalidate specific paths in a distribution.

const { CloudFrontClient, CreateInvalidationCommand } = require('@aws-sdk/client-cloudfront');

const client = new CloudFrontClient({ region: 'us-east-1' });

const params = {
  DistributionId: 'EXAMPLE_DIST_ID',
  InvalidationBatch: {
    CallerReference: 'unique-string',
    Paths: {
      Quantity: 1,
      Items: ['/path/to/invalidate']
    }
  }
};

const run = async () => {
  try {
    const data = await client.send(new CreateInvalidationCommand(params));
    console.log('Invalidation created:', data);
  } catch (err) {
    console.error('Error creating invalidation:', err);
  }
};

run();

Other packages similar to @aws-sdk/client-cloudfront

FAQs

Package last updated on 11 Oct 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc