Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@aws-sdk/client-cloudfront
Advanced tools
@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.
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();
The 'cloudflare' npm package allows developers to interact with Cloudflare's CDN and other services. It provides functionalities similar to @aws-sdk/client-cloudfront, such as managing DNS records, creating and managing zones, and purging cache. However, it is specific to Cloudflare's infrastructure.
The 'fastly' npm package provides an interface to interact with Fastly's CDN services. It offers functionalities like creating and managing services, purging cache, and configuring domains. This package is specific to Fastly's CDN platform and offers similar capabilities to @aws-sdk/client-cloudfront but within the Fastly ecosystem.
The 'akamai-edgegrid' npm package allows developers to interact with Akamai's CDN and other services. It provides functionalities for managing edge configurations, purging cache, and monitoring traffic. This package is tailored for Akamai's platform and offers similar CDN management capabilities as @aws-sdk/client-cloudfront.
FAQs
AWS SDK for JavaScript Cloudfront Client for Node.js, Browser and React Native
The npm package @aws-sdk/client-cloudfront receives a total of 314,966 weekly downloads. As such, @aws-sdk/client-cloudfront popularity was classified as popular.
We found that @aws-sdk/client-cloudfront demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.