CachePolicy class
Example Usage
Use the aws.cloudfront.CachePolicy resource to create a cache policy for CloudFront.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.cloudfront.CachePolicy("example", {
parametersInCacheKeyAndForwardedToOrigin: {
cookiesConfig: {
cookies: {
items: ["example"],
},
cookieBehavior: "whitelist",
},
headersConfig: {
headers: {
items: ["example"],
},
headerBehavior: "whitelist",
},
queryStringsConfig: {
queryStrings: {
items: ["example"],
},
queryStringBehavior: "whitelist",
},
},
name: "example-policy",
comment: "test comment",
defaultTtl: 50,
maxTtl: 100,
minTtl: 1,
});
import pulumi
import pulumi_aws as aws
example = aws.cloudfront.CachePolicy("example",
parameters_in_cache_key_and_forwarded_to_origin={
"cookies_config": {
"cookies": {
"items": ["example"],
},
"cookie_behavior": "whitelist",
},
"headers_config": {
"headers": {
"items": ["example"],
},
"header_behavior": "whitelist",
},
"query_strings_config": {
"query_strings": {
"items": ["example"],
},
"query_string_behavior": "whitelist",
},
},
name="example-policy",
comment="test comment",
default_ttl=50,
max_ttl=100,
min_ttl=1)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new Aws.CloudFront.CachePolicy("example", new()
{
ParametersInCacheKeyAndForwardedToOrigin = new Aws.CloudFront.Inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginArgs
{
CookiesConfig = new Aws.CloudFront.Inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginCookiesConfigArgs
{
Cookies = new Aws.CloudFront.Inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginCookiesConfigCookiesArgs
{
Items = new[]
{
"example",
},
},
CookieBehavior = "whitelist",
},
HeadersConfig = new Aws.CloudFront.Inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginHeadersConfigArgs
{
Headers = new Aws.CloudFront.Inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginHeadersConfigHeadersArgs
{
Items = new[]
{
"example",
},
},
HeaderBehavior = "whitelist",
},
QueryStringsConfig = new Aws.CloudFront.Inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginQueryStringsConfigArgs
{
QueryStrings = new Aws.CloudFront.Inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginQueryStringsConfigQueryStringsArgs
{
Items = new[]
{
"example",
},
},
QueryStringBehavior = "whitelist",
},
},
Name = "example-policy",
Comment = "test comment",
DefaultTtl = 50,
MaxTtl = 100,
MinTtl = 1,
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/cloudfront"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := cloudfront.NewCachePolicy(ctx, "example", &cloudfront.CachePolicyArgs{
ParametersInCacheKeyAndForwardedToOrigin: &cloudfront.CachePolicyParametersInCacheKeyAndForwardedToOriginArgs{
CookiesConfig: &cloudfront.CachePolicyParametersInCacheKeyAndForwardedToOriginCookiesConfigArgs{
Cookies: &cloudfront.CachePolicyParametersInCacheKeyAndForwardedToOriginCookiesConfigCookiesArgs{
Items: pulumi.StringArray{
pulumi.String("example"),
},
},
CookieBehavior: pulumi.String("whitelist"),
},
HeadersConfig: &cloudfront.CachePolicyParametersInCacheKeyAndForwardedToOriginHeadersConfigArgs{
Headers: &cloudfront.CachePolicyParametersInCacheKeyAndForwardedToOriginHeadersConfigHeadersArgs{
Items: pulumi.StringArray{
pulumi.String("example"),
},
},
HeaderBehavior: pulumi.String("whitelist"),
},
QueryStringsConfig: &cloudfront.CachePolicyParametersInCacheKeyAndForwardedToOriginQueryStringsConfigArgs{
QueryStrings: &cloudfront.CachePolicyParametersInCacheKeyAndForwardedToOriginQueryStringsConfigQueryStringsArgs{
Items: pulumi.StringArray{
pulumi.String("example"),
},
},
QueryStringBehavior: pulumi.String("whitelist"),
},
},
Name: pulumi.String("example-policy"),
Comment: pulumi.String("test comment"),
DefaultTtl: pulumi.Int(50),
MaxTtl: pulumi.Int(100),
MinTtl: pulumi.Int(1),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_cloudfront_cachepolicy" "example" {
parameters_in_cache_key_and_forwarded_to_origin = {
cookies_config = {
cookies = {
items = ["example"]
}
cookie_behavior = "whitelist"
}
headers_config = {
headers = {
items = ["example"]
}
header_behavior = "whitelist"
}
query_strings_config = {
query_strings = {
items = ["example"]
}
query_string_behavior = "whitelist"
}
}
name = "example-policy"
comment = "test comment"
default_ttl = 50
max_ttl = 100
min_ttl = 1
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.cloudfront.CachePolicy;
import com.pulumi.aws.cloudfront.CachePolicyArgs;
import com.pulumi.aws.cloudfront.inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginArgs;
import com.pulumi.aws.cloudfront.inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginCookiesConfigArgs;
import com.pulumi.aws.cloudfront.inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginCookiesConfigCookiesArgs;
import com.pulumi.aws.cloudfront.inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginHeadersConfigArgs;
import com.pulumi.aws.cloudfront.inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginHeadersConfigHeadersArgs;
import com.pulumi.aws.cloudfront.inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginQueryStringsConfigArgs;
import com.pulumi.aws.cloudfront.inputs.CachePolicyParametersInCacheKeyAndForwardedToOriginQueryStringsConfigQueryStringsArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new CachePolicy("example", CachePolicyArgs.builder()
.parametersInCacheKeyAndForwardedToOrigin(CachePolicyParametersInCacheKeyAndForwardedToOriginArgs.builder()
.cookiesConfig(CachePolicyParametersInCacheKeyAndForwardedToOriginCookiesConfigArgs.builder()
.cookies(CachePolicyParametersInCacheKeyAndForwardedToOriginCookiesConfigCookiesArgs.builder()
.items("example")
.build())
.cookieBehavior("whitelist")
.build())
.headersConfig(CachePolicyParametersInCacheKeyAndForwardedToOriginHeadersConfigArgs.builder()
.headers(CachePolicyParametersInCacheKeyAndForwardedToOriginHeadersConfigHeadersArgs.builder()
.items("example")
.build())
.headerBehavior("whitelist")
.build())
.queryStringsConfig(CachePolicyParametersInCacheKeyAndForwardedToOriginQueryStringsConfigArgs.builder()
.queryStrings(CachePolicyParametersInCacheKeyAndForwardedToOriginQueryStringsConfigQueryStringsArgs.builder()
.items("example")
.build())
.queryStringBehavior("whitelist")
.build())
.build())
.name("example-policy")
.comment("test comment")
.defaultTtl(50)
.maxTtl(100)
.minTtl(1)
.build());
}
}
resources:
example:
type: aws:cloudfront:CachePolicy
properties:
parametersInCacheKeyAndForwardedToOrigin:
cookiesConfig:
cookies:
items:
- example
cookieBehavior: whitelist
headersConfig:
headers:
items:
- example
headerBehavior: whitelist
queryStringsConfig:
queryStrings:
items:
- example
queryStringBehavior: whitelist
name: example-policy
comment: test comment
defaultTtl: 50
maxTtl: 100
minTtl: 1
Import
Using pulumi import, import CloudFront cache policies using the id of the cache policy. For example:
$ pulumi import aws:cloudfront/cachePolicy:CachePolicy policy 658327ea-f89d-4fab-a63d-7e88639e58f6
Constructors
- CachePolicy(String name, {CachePolicyArgs? args, CustomResourceOptions? options})
-
Creates a new CachePolicy.
nameThe Pulumi resource name.argsArguments used to configure this CachePolicy. The set of arguments for CachePolicy.optionsResource options controlling this resource's behavior. - CachePolicy.reference(String urn)
- Creates a typed reference to an existing CachePolicy resource.
Properties
-
arn
↔ Output<
String> -
The cache policy ARN.
latefinal
-
childResources
→ Set<
Resource> -
finalinherited
-
comment
↔ Output<
String?> -
Description for the cache policy.
latefinal
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
defaultTtl
↔ Output<
int?> -
Amount of time, in seconds, that objects are allowed to remain in the CloudFront cache before CloudFront sends a new request to the origin server to check if the object has been updated.
latefinal
-
etag
↔ Output<
String> -
Current version of the cache policy.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
maxTtl
↔ Output<
int?> -
Maximum amount of time, in seconds, that objects stay in the CloudFront cache before CloudFront sends another request to the origin to see if the object has been updated.
latefinal
-
minTtl
↔ Output<
int?> -
Minimum amount of time, in seconds, that objects should remain in the CloudFront cache before a new request is sent to the origin to check for updates.
latefinal
-
name
↔ Output<
String> -
Unique name used to identify the cache policy.
latefinal
-
parametersInCacheKeyAndForwardedToOrigin
↔ Output<
CachePolicyParametersInCacheKeyAndForwardedToOrigin> -
Configuration for including HTTP headers, cookies, and URL query strings in the cache key. For more information, refer to the Parameters In Cache Key And Forwarded To Origin section.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {CachePolicyState? state, CustomResourceOptions? options}) → CachePolicy -
Gets an existing CachePolicy resource's state with the given
nameandid.