UNPKG

@pulumi/aws

Version:

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

457 lines • 18.8 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, Object.assign(Object.assign({}, 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 ? state.aliases : undefined; resourceInputs["anycastIpListId"] = state ? state.anycastIpListId : undefined; resourceInputs["arn"] = state ? state.arn : undefined; resourceInputs["callerReference"] = state ? state.callerReference : undefined; resourceInputs["comment"] = state ? state.comment : undefined; resourceInputs["continuousDeploymentPolicyId"] = state ? state.continuousDeploymentPolicyId : undefined; resourceInputs["customErrorResponses"] = state ? state.customErrorResponses : undefined; resourceInputs["defaultCacheBehavior"] = state ? state.defaultCacheBehavior : undefined; resourceInputs["defaultRootObject"] = state ? state.defaultRootObject : undefined; resourceInputs["domainName"] = state ? state.domainName : undefined; resourceInputs["enabled"] = state ? state.enabled : undefined; resourceInputs["etag"] = state ? state.etag : undefined; resourceInputs["hostedZoneId"] = state ? state.hostedZoneId : undefined; resourceInputs["httpVersion"] = state ? state.httpVersion : undefined; resourceInputs["inProgressValidationBatches"] = state ? state.inProgressValidationBatches : undefined; resourceInputs["isIpv6Enabled"] = state ? state.isIpv6Enabled : undefined; resourceInputs["lastModifiedTime"] = state ? state.lastModifiedTime : undefined; resourceInputs["loggingConfig"] = state ? state.loggingConfig : undefined; resourceInputs["orderedCacheBehaviors"] = state ? state.orderedCacheBehaviors : undefined; resourceInputs["originGroups"] = state ? state.originGroups : undefined; resourceInputs["origins"] = state ? state.origins : undefined; resourceInputs["priceClass"] = state ? state.priceClass : undefined; resourceInputs["restrictions"] = state ? state.restrictions : undefined; resourceInputs["retainOnDelete"] = state ? state.retainOnDelete : undefined; resourceInputs["staging"] = state ? state.staging : undefined; resourceInputs["status"] = state ? state.status : undefined; resourceInputs["tags"] = state ? state.tags : undefined; resourceInputs["tagsAll"] = state ? state.tagsAll : undefined; resourceInputs["trustedKeyGroups"] = state ? state.trustedKeyGroups : undefined; resourceInputs["trustedSigners"] = state ? state.trustedSigners : undefined; resourceInputs["viewerCertificate"] = state ? state.viewerCertificate : undefined; resourceInputs["waitForDeployment"] = state ? state.waitForDeployment : undefined; resourceInputs["webAclId"] = state ? state.webAclId : undefined; } else { const args = argsOrState; if ((!args || args.defaultCacheBehavior === undefined) && !opts.urn) { throw new Error("Missing required property 'defaultCacheBehavior'"); } if ((!args || args.enabled === undefined) && !opts.urn) { throw new Error("Missing required property 'enabled'"); } if ((!args || args.origins === undefined) && !opts.urn) { throw new Error("Missing required property 'origins'"); } if ((!args || args.restrictions === undefined) && !opts.urn) { throw new Error("Missing required property 'restrictions'"); } if ((!args || args.viewerCertificate === undefined) && !opts.urn) { throw new Error("Missing required property 'viewerCertificate'"); } resourceInputs["aliases"] = args ? args.aliases : undefined; resourceInputs["anycastIpListId"] = args ? args.anycastIpListId : undefined; resourceInputs["comment"] = args ? args.comment : undefined; resourceInputs["continuousDeploymentPolicyId"] = args ? args.continuousDeploymentPolicyId : undefined; resourceInputs["customErrorResponses"] = args ? args.customErrorResponses : undefined; resourceInputs["defaultCacheBehavior"] = args ? args.defaultCacheBehavior : undefined; resourceInputs["defaultRootObject"] = args ? args.defaultRootObject : undefined; resourceInputs["enabled"] = args ? args.enabled : undefined; resourceInputs["httpVersion"] = args ? args.httpVersion : undefined; resourceInputs["isIpv6Enabled"] = args ? args.isIpv6Enabled : undefined; resourceInputs["loggingConfig"] = args ? args.loggingConfig : undefined; resourceInputs["orderedCacheBehaviors"] = args ? args.orderedCacheBehaviors : undefined; resourceInputs["originGroups"] = args ? args.originGroups : undefined; resourceInputs["origins"] = args ? args.origins : undefined; resourceInputs["priceClass"] = args ? args.priceClass : undefined; resourceInputs["restrictions"] = args ? args.restrictions : undefined; resourceInputs["retainOnDelete"] = args ? args.retainOnDelete : undefined; resourceInputs["staging"] = args ? args.staging : undefined; resourceInputs["tags"] = args ? args.tags : undefined; resourceInputs["viewerCertificate"] = args ? args.viewerCertificate : undefined; resourceInputs["waitForDeployment"] = args ? args.waitForDeployment : undefined; resourceInputs["webAclId"] = args ? args.webAclId : undefined; 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