ResponseHeadersPolicy

class aws_cdk.aws_cloudfront.ResponseHeadersPolicy(scope, id, *, comment=None, cors_behavior=None, custom_headers_behavior=None, response_headers_policy_name=None, security_headers_behavior=None)

Bases: aws_cdk.core.Resource

A Response Headers Policy configuration.

ExampleMetadata

infused

Resource

AWS::CloudFront::ResponseHeadersPolicy

Example:

# Using an existing managed response headers policy
# bucket_origin: origins.S3Origin

cloudfront.Distribution(self, "myDistManagedPolicy",
    default_behavior=cloudfront.BehaviorOptions(
        origin=bucket_origin,
        response_headers_policy=cloudfront.ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS
    )
)

# Creating a custom response headers policy -- all parameters optional
my_response_headers_policy = cloudfront.ResponseHeadersPolicy(self, "ResponseHeadersPolicy",
    response_headers_policy_name="MyPolicy",
    comment="A default policy",
    cors_behavior=cloudfront.ResponseHeadersCorsBehavior(
        access_control_allow_credentials=False,
        access_control_allow_headers=["X-Custom-Header-1", "X-Custom-Header-2"],
        access_control_allow_methods=["GET", "POST"],
        access_control_allow_origins=["*"],
        access_control_expose_headers=["X-Custom-Header-1", "X-Custom-Header-2"],
        access_control_max_age=Duration.seconds(600),
        origin_override=True
    ),
    custom_headers_behavior=cloudfront.ResponseCustomHeadersBehavior(
        custom_headers=[cloudfront.ResponseCustomHeader(header="X-Amz-Date", value="some-value", override=True), cloudfront.ResponseCustomHeader(header="X-Amz-Security-Token", value="some-value", override=False)
        ]
    ),
    security_headers_behavior=cloudfront.ResponseSecurityHeadersBehavior(
        content_security_policy=cloudfront.ResponseHeadersContentSecurityPolicy(content_security_policy="default-src https:;", override=True),
        content_type_options=cloudfront.ResponseHeadersContentTypeOptions(override=True),
        frame_options=cloudfront.ResponseHeadersFrameOptions(frame_option=cloudfront.HeadersFrameOption.DENY, override=True),
        referrer_policy=cloudfront.ResponseHeadersReferrerPolicy(referrer_policy=cloudfront.HeadersReferrerPolicy.NO_REFERRER, override=True),
        strict_transport_security=cloudfront.ResponseHeadersStrictTransportSecurity(access_control_max_age=Duration.seconds(600), include_subdomains=True, override=True),
        xss_protection=cloudfront.ResponseHeadersXSSProtection(protection=True, mode_block=True, report_uri="https://example.com/csp-report", override=True)
    )
)
cloudfront.Distribution(self, "myDistCustomPolicy",
    default_behavior=cloudfront.BehaviorOptions(
        origin=bucket_origin,
        response_headers_policy=my_response_headers_policy
    )
)
Parameters
  • scope (Construct) –

  • id (str) –

  • comment (Optional[str]) – A comment to describe the response headers policy. Default: - no comment

  • cors_behavior (Optional[ResponseHeadersCorsBehavior]) – A configuration for a set of HTTP response headers that are used for cross-origin resource sharing (CORS). Default: - no cors behavior

  • custom_headers_behavior (Optional[ResponseCustomHeadersBehavior]) – A configuration for a set of custom HTTP response headers. Default: - no custom headers behavior

  • response_headers_policy_name (Optional[str]) – A unique name to identify the response headers policy. Default: - generated from the id

  • security_headers_behavior (Optional[ResponseSecurityHeadersBehavior]) – A configuration for a set of security-related HTTP response headers. Default: - no security headers behavior

Methods

apply_removal_policy(policy)

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you’ve removed it from the CDK application or because you’ve made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

Parameters

policy (RemovalPolicy) –

Return type

None

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

CORS_ALLOW_ALL_ORIGINS = <jsii._reference_map.InterfaceDynamicProxy object>
CORS_ALLOW_ALL_ORIGINS_AND_SECURITY_HEADERS = <jsii._reference_map.InterfaceDynamicProxy object>
CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT = <jsii._reference_map.InterfaceDynamicProxy object>
CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS = <jsii._reference_map.InterfaceDynamicProxy object>
SECURITY_HEADERS = <jsii._reference_map.InterfaceDynamicProxy object>
env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

Return type

ResourceEnvironment

node

The construct tree node associated with this construct.

Return type

ConstructNode

response_headers_policy_id

The ID of the response headers policy.

Return type

str

stack

The stack in which this resource is defined.

Return type

Stack

Static Methods

classmethod from_response_headers_policy_id(scope, id, response_headers_policy_id)

Import an existing Response Headers Policy from its ID.

Parameters
  • scope (Construct) –

  • id (str) –

  • response_headers_policy_id (str) –

Return type

IResponseHeadersPolicy

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters

x (Any) –

Return type

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters

construct (IConstruct) –

Return type

bool