UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

457 lines • 17.7 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.Distribution = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * Creates an Amazon CloudFront web distribution. * * For information about CloudFront distributions, see the [Amazon CloudFront Developer Guide](http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html). For specific information about creating CloudFront web distributions, see the [POST Distribution](https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CreateDistribution.html) page in the Amazon CloudFront API Reference. * * > **NOTE:** CloudFront distributions take about 15 minutes to reach a deployed state after creation or modification. During this time, deletes to resources will be blocked. If you need to delete a distribution that is enabled and you do not want to wait, you need to use the `retainOnDelete` flag. * * ## Example Usage * * ### S3 Origin * * The example below creates a CloudFront distribution with an S3 origin. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const b = new aws.s3.Bucket("b", { * bucket: "mybucket", * tags: { * Name: "My bucket", * }, * }); * const bAcl = new aws.s3.BucketAcl("b_acl", { * bucket: b.id, * acl: "private", * }); * const s3OriginId = "myS3Origin"; * const s3Distribution = new aws.cloudfront.Distribution("s3_distribution", { * origins: [{ * domainName: b.bucketRegionalDomainName, * originAccessControlId: _default.id, * originId: s3OriginId, * }], * enabled: true, * isIpv6Enabled: true, * comment: "Some comment", * defaultRootObject: "index.html", * loggingConfig: { * includeCookies: false, * bucket: "mylogs.s3.amazonaws.com", * prefix: "myprefix", * }, * aliases: [ * "mysite.example.com", * "yoursite.example.com", * ], * defaultCacheBehavior: { * allowedMethods: [ * "DELETE", * "GET", * "HEAD", * "OPTIONS", * "PATCH", * "POST", * "PUT", * ], * cachedMethods: [ * "GET", * "HEAD", * ], * targetOriginId: s3OriginId, * forwardedValues: { * queryString: false, * cookies: { * forward: "none", * }, * }, * viewerProtocolPolicy: "allow-all", * minTtl: 0, * defaultTtl: 3600, * maxTtl: 86400, * }, * orderedCacheBehaviors: [ * { * pathPattern: "/content/immutable/*", * allowedMethods: [ * "GET", * "HEAD", * "OPTIONS", * ], * cachedMethods: [ * "GET", * "HEAD", * "OPTIONS", * ], * targetOriginId: s3OriginId, * forwardedValues: { * queryString: false, * headers: ["Origin"], * cookies: { * forward: "none", * }, * }, * minTtl: 0, * defaultTtl: 86400, * maxTtl: 31536000, * compress: true, * viewerProtocolPolicy: "redirect-to-https", * }, * { * pathPattern: "/content/*", * allowedMethods: [ * "GET", * "HEAD", * "OPTIONS", * ], * cachedMethods: [ * "GET", * "HEAD", * ], * targetOriginId: s3OriginId, * forwardedValues: { * queryString: false, * cookies: { * forward: "none", * }, * }, * minTtl: 0, * defaultTtl: 3600, * maxTtl: 86400, * compress: true, * viewerProtocolPolicy: "redirect-to-https", * }, * ], * priceClass: "PriceClass_200", * restrictions: { * geoRestriction: { * restrictionType: "whitelist", * locations: [ * "US", * "CA", * "GB", * "DE", * ], * }, * }, * tags: { * Environment: "production", * }, * viewerCertificate: { * cloudfrontDefaultCertificate: true, * }, * }); * ``` * * ### With Failover Routing * * The example below creates a CloudFront distribution with an origin group for failover routing. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const s3Distribution = new aws.cloudfront.Distribution("s3_distribution", { * originGroups: [{ * originId: "groupS3", * failoverCriteria: { * statusCodes: [ * 403, * 404, * 500, * 502, * ], * }, * members: [ * { * originId: "primaryS3", * }, * { * originId: "failoverS3", * }, * ], * }], * origins: [ * { * domainName: primary.bucketRegionalDomainName, * originId: "primaryS3", * s3OriginConfig: { * originAccessIdentity: _default.cloudfrontAccessIdentityPath, * }, * }, * { * domainName: failover.bucketRegionalDomainName, * originId: "failoverS3", * s3OriginConfig: { * originAccessIdentity: _default.cloudfrontAccessIdentityPath, * }, * }, * ], * defaultCacheBehavior: { * targetOriginId: "groupS3", * }, * }); * ``` * * ### With Managed Caching Policy * * The example below creates a CloudFront distribution with an [AWS managed caching policy](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html). * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const s3OriginId = "myS3Origin"; * const s3Distribution = new aws.cloudfront.Distribution("s3_distribution", { * origins: [{ * domainName: primary.bucketRegionalDomainName, * originId: "myS3Origin", * s3OriginConfig: { * originAccessIdentity: _default.cloudfrontAccessIdentityPath, * }, * }], * enabled: true, * isIpv6Enabled: true, * comment: "Some comment", * defaultRootObject: "index.html", * defaultCacheBehavior: { * cachePolicyId: "4135ea2d-6df8-44a3-9df3-4b5a84be39ad", * allowedMethods: [ * "GET", * "HEAD", * "OPTIONS", * ], * cachedMethods: [ * "GET", * "HEAD", * ], * targetOriginId: s3OriginId, * viewerProtocolPolicy: "allow-all", * }, * restrictions: { * geoRestriction: { * restrictionType: "whitelist", * locations: [ * "US", * "CA", * "GB", * "DE", * ], * }, * }, * viewerCertificate: { * cloudfrontDefaultCertificate: true, * }, * }); * ``` * * ### With V2 logging to S3 * * The example below creates a CloudFront distribution with [standard logging V2 to S3](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/standard-logging.html#enable-access-logging-api). * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.cloudfront.Distribution("example", {}); * const exampleLogDeliverySource = new aws.cloudwatch.LogDeliverySource("example", { * region: "us-east-1", * name: "example", * logType: "ACCESS_LOGS", * resourceArn: example.arn, * }); * const exampleBucket = new aws.s3.Bucket("example", { * bucket: "testbucket", * forceDestroy: true, * }); * const exampleLogDeliveryDestination = new aws.cloudwatch.LogDeliveryDestination("example", { * region: "us-east-1", * name: "s3-destination", * outputFormat: "parquet", * deliveryDestinationConfiguration: { * destinationResourceArn: pulumi.interpolate`${exampleBucket.arn}/prefix`, * }, * }); * const exampleLogDelivery = new aws.cloudwatch.LogDelivery("example", { * region: "us-east-1", * deliverySourceName: exampleLogDeliverySource.name, * deliveryDestinationArn: exampleLogDeliveryDestination.arn, * s3DeliveryConfigurations: [{ * suffixPath: "/123456678910/{DistributionId}/{yyyy}/{MM}/{dd}/{HH}", * }], * }); * ``` * * ### With V2 logging to Data Firehose * * The example below creates a CloudFront distribution with [standard logging V2 to Data Firehose](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/standard-logging.html#enable-access-logging-api). * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.cloudfront.Distribution("example", {}); * const cloudfrontLogs = new aws.kinesis.FirehoseDeliveryStream("cloudfront_logs", { * region: "us-east-1", * tags: { * LogDeliveryEnabled: "true", * }, * }); * const exampleLogDeliverySource = new aws.cloudwatch.LogDeliverySource("example", { * region: "us-east-1", * name: "cloudfront-logs-source", * logType: "ACCESS_LOGS", * resourceArn: example.arn, * }); * const exampleLogDeliveryDestination = new aws.cloudwatch.LogDeliveryDestination("example", { * region: "us-east-1", * name: "firehose-destination", * outputFormat: "json", * deliveryDestinationConfiguration: { * destinationResourceArn: cloudfrontLogs.arn, * }, * }); * const exampleLogDelivery = new aws.cloudwatch.LogDelivery("example", { * region: "us-east-1", * deliverySourceName: exampleLogDeliverySource.name, * deliveryDestinationArn: exampleLogDeliveryDestination.arn, * }); * ``` * * ## Import * * Using `pulumi import`, import CloudFront Distributions using the `id`. For example: * * ```sh * $ pulumi import aws:cloudfront/distribution:Distribution distribution E74FTE3EXAMPLE * ``` */ class Distribution extends pulumi.CustomResource { /** * Get an existing Distribution resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param state Any extra arguments used during the lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name, id, state, opts) { return new Distribution(name, state, { ...opts, id: id }); } /** * Returns true if the given object is an instance of Distribution. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === Distribution.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["aliases"] = state?.aliases; resourceInputs["anycastIpListId"] = state?.anycastIpListId; resourceInputs["arn"] = state?.arn; resourceInputs["callerReference"] = state?.callerReference; resourceInputs["comment"] = state?.comment; resourceInputs["continuousDeploymentPolicyId"] = state?.continuousDeploymentPolicyId; resourceInputs["customErrorResponses"] = state?.customErrorResponses; resourceInputs["defaultCacheBehavior"] = state?.defaultCacheBehavior; resourceInputs["defaultRootObject"] = state?.defaultRootObject; resourceInputs["domainName"] = state?.domainName; resourceInputs["enabled"] = state?.enabled; resourceInputs["etag"] = state?.etag; resourceInputs["hostedZoneId"] = state?.hostedZoneId; resourceInputs["httpVersion"] = state?.httpVersion; resourceInputs["inProgressValidationBatches"] = state?.inProgressValidationBatches; resourceInputs["isIpv6Enabled"] = state?.isIpv6Enabled; resourceInputs["lastModifiedTime"] = state?.lastModifiedTime; resourceInputs["loggingConfig"] = state?.loggingConfig; resourceInputs["orderedCacheBehaviors"] = state?.orderedCacheBehaviors; resourceInputs["originGroups"] = state?.originGroups; resourceInputs["origins"] = state?.origins; resourceInputs["priceClass"] = state?.priceClass; resourceInputs["restrictions"] = state?.restrictions; resourceInputs["retainOnDelete"] = state?.retainOnDelete; resourceInputs["staging"] = state?.staging; resourceInputs["status"] = state?.status; resourceInputs["tags"] = state?.tags; resourceInputs["tagsAll"] = state?.tagsAll; resourceInputs["trustedKeyGroups"] = state?.trustedKeyGroups; resourceInputs["trustedSigners"] = state?.trustedSigners; resourceInputs["viewerCertificate"] = state?.viewerCertificate; resourceInputs["waitForDeployment"] = state?.waitForDeployment; resourceInputs["webAclId"] = state?.webAclId; } else { const args = argsOrState; if (args?.defaultCacheBehavior === undefined && !opts.urn) { throw new Error("Missing required property 'defaultCacheBehavior'"); } if (args?.enabled === undefined && !opts.urn) { throw new Error("Missing required property 'enabled'"); } if (args?.origins === undefined && !opts.urn) { throw new Error("Missing required property 'origins'"); } if (args?.restrictions === undefined && !opts.urn) { throw new Error("Missing required property 'restrictions'"); } if (args?.viewerCertificate === undefined && !opts.urn) { throw new Error("Missing required property 'viewerCertificate'"); } resourceInputs["aliases"] = args?.aliases; resourceInputs["anycastIpListId"] = args?.anycastIpListId; resourceInputs["comment"] = args?.comment; resourceInputs["continuousDeploymentPolicyId"] = args?.continuousDeploymentPolicyId; resourceInputs["customErrorResponses"] = args?.customErrorResponses; resourceInputs["defaultCacheBehavior"] = args?.defaultCacheBehavior; resourceInputs["defaultRootObject"] = args?.defaultRootObject; resourceInputs["enabled"] = args?.enabled; resourceInputs["httpVersion"] = args?.httpVersion; resourceInputs["isIpv6Enabled"] = args?.isIpv6Enabled; resourceInputs["loggingConfig"] = args?.loggingConfig; resourceInputs["orderedCacheBehaviors"] = args?.orderedCacheBehaviors; resourceInputs["originGroups"] = args?.originGroups; resourceInputs["origins"] = args?.origins; resourceInputs["priceClass"] = args?.priceClass; resourceInputs["restrictions"] = args?.restrictions; resourceInputs["retainOnDelete"] = args?.retainOnDelete; resourceInputs["staging"] = args?.staging; resourceInputs["tags"] = args?.tags; resourceInputs["viewerCertificate"] = args?.viewerCertificate; resourceInputs["waitForDeployment"] = args?.waitForDeployment; resourceInputs["webAclId"] = args?.webAclId; resourceInputs["arn"] = undefined /*out*/; resourceInputs["callerReference"] = undefined /*out*/; resourceInputs["domainName"] = undefined /*out*/; resourceInputs["etag"] = undefined /*out*/; resourceInputs["hostedZoneId"] = undefined /*out*/; resourceInputs["inProgressValidationBatches"] = undefined /*out*/; resourceInputs["lastModifiedTime"] = undefined /*out*/; resourceInputs["status"] = undefined /*out*/; resourceInputs["tagsAll"] = undefined /*out*/; resourceInputs["trustedKeyGroups"] = undefined /*out*/; resourceInputs["trustedSigners"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(Distribution.__pulumiType, name, resourceInputs, opts); } } exports.Distribution = Distribution; /** @internal */ Distribution.__pulumiType = 'aws:cloudfront/distribution:Distribution'; //# sourceMappingURL=distribution.js.map