Interface SourceConfiguration

All Superinterfaces:
software.amazon.jsii.JsiiSerializable
All Known Implementing Classes:
SourceConfiguration.Jsii$Proxy

@Generated(value="jsii-pacmak/1.97.0 (build 729de35)", date="2024-04-24T21:00:26.738Z") @Stability(Stable) public interface SourceConfiguration extends software.amazon.jsii.JsiiSerializable
A source configuration is a wrapper for CloudFront origins and behaviors.

An origin is what CloudFront will "be in front of" - that is, CloudFront will pull it's assets from an origin.

If you're using s3 as a source - pass the s3Origin property, otherwise, pass the customOriginSource property.

One or the other must be passed, and it is invalid to pass both in the same SourceConfiguration.

Example:

 // The code below shows an example of how to instantiate this type.
 // The values are placeholders you should change.
 import software.amazon.awscdk.*;
 import software.amazon.awscdk.services.cloudfront.*;
 import software.amazon.awscdk.services.lambda.*;
 import software.amazon.awscdk.services.s3.*;
 Bucket bucket;
 Function function_;
 KeyGroup keyGroup;
 OriginAccessIdentity originAccessIdentity;
 Version version;
 SourceConfiguration sourceConfiguration = SourceConfiguration.builder()
         .behaviors(List.of(Behavior.builder()
                 .allowedMethods(CloudFrontAllowedMethods.GET_HEAD)
                 .cachedMethods(CloudFrontAllowedCachedMethods.GET_HEAD)
                 .compress(false)
                 .defaultTtl(Duration.minutes(30))
                 .forwardedValues(ForwardedValuesProperty.builder()
                         .queryString(false)
                         // the properties below are optional
                         .cookies(CookiesProperty.builder()
                                 .forward("forward")
                                 // the properties below are optional
                                 .whitelistedNames(List.of("whitelistedNames"))
                                 .build())
                         .headers(List.of("headers"))
                         .queryStringCacheKeys(List.of("queryStringCacheKeys"))
                         .build())
                 .functionAssociations(List.of(FunctionAssociation.builder()
                         .eventType(FunctionEventType.VIEWER_REQUEST)
                         .function(function_)
                         .build()))
                 .isDefaultBehavior(false)
                 .lambdaFunctionAssociations(List.of(LambdaFunctionAssociation.builder()
                         .eventType(LambdaEdgeEventType.ORIGIN_REQUEST)
                         .lambdaFunction(version)
                         // the properties below are optional
                         .includeBody(false)
                         .build()))
                 .maxTtl(Duration.minutes(30))
                 .minTtl(Duration.minutes(30))
                 .pathPattern("pathPattern")
                 .trustedKeyGroups(List.of(keyGroup))
                 .trustedSigners(List.of("trustedSigners"))
                 .viewerProtocolPolicy(ViewerProtocolPolicy.HTTPS_ONLY)
                 .build()))
         // the properties below are optional
         .connectionAttempts(123)
         .connectionTimeout(Duration.minutes(30))
         .customOriginSource(CustomOriginConfig.builder()
                 .domainName("domainName")
                 // the properties below are optional
                 .allowedOriginSSLVersions(List.of(OriginSslPolicy.SSL_V3))
                 .httpPort(123)
                 .httpsPort(123)
                 .originHeaders(Map.of(
                         "originHeadersKey", "originHeaders"))
                 .originKeepaliveTimeout(Duration.minutes(30))
                 .originPath("originPath")
                 .originProtocolPolicy(OriginProtocolPolicy.HTTP_ONLY)
                 .originReadTimeout(Duration.minutes(30))
                 .originShieldRegion("originShieldRegion")
                 .build())
         .failoverCriteriaStatusCodes(List.of(FailoverStatusCode.FORBIDDEN))
         .failoverCustomOriginSource(CustomOriginConfig.builder()
                 .domainName("domainName")
                 // the properties below are optional
                 .allowedOriginSSLVersions(List.of(OriginSslPolicy.SSL_V3))
                 .httpPort(123)
                 .httpsPort(123)
                 .originHeaders(Map.of(
                         "originHeadersKey", "originHeaders"))
                 .originKeepaliveTimeout(Duration.minutes(30))
                 .originPath("originPath")
                 .originProtocolPolicy(OriginProtocolPolicy.HTTP_ONLY)
                 .originReadTimeout(Duration.minutes(30))
                 .originShieldRegion("originShieldRegion")
                 .build())
         .failoverS3OriginSource(S3OriginConfig.builder()
                 .s3BucketSource(bucket)
                 // the properties below are optional
                 .originAccessIdentity(originAccessIdentity)
                 .originHeaders(Map.of(
                         "originHeadersKey", "originHeaders"))
                 .originPath("originPath")
                 .originShieldRegion("originShieldRegion")
                 .build())
         .originShieldRegion("originShieldRegion")
         .s3OriginSource(S3OriginConfig.builder()
                 .s3BucketSource(bucket)
                 // the properties below are optional
                 .originAccessIdentity(originAccessIdentity)
                 .originHeaders(Map.of(
                         "originHeadersKey", "originHeaders"))
                 .originPath("originPath")
                 .originShieldRegion("originShieldRegion")
                 .build())
         .build();
 
  • Method Details

    • getBehaviors

      @Stability(Stable) @NotNull List<Behavior> getBehaviors()
      The behaviors associated with this source.

      At least one (default) behavior must be included.

    • getConnectionAttempts

      @Stability(Stable) @Nullable default Number getConnectionAttempts()
      The number of times that CloudFront attempts to connect to the origin.

      You can specify 1, 2, or 3 as the number of attempts.

      Default: 3

    • getConnectionTimeout

      @Stability(Stable) @Nullable default Duration getConnectionTimeout()
      The number of seconds that CloudFront waits when trying to establish a connection to the origin.

      You can specify a number of seconds between 1 and 10 (inclusive).

      Default: cdk.Duration.seconds(10)

    • getCustomOriginSource

      @Stability(Stable) @Nullable default CustomOriginConfig getCustomOriginSource()
      A custom origin source - for all non-s3 sources.
    • getFailoverCriteriaStatusCodes

      @Stability(Stable) @Nullable default List<FailoverStatusCode> getFailoverCriteriaStatusCodes()
      HTTP status code to failover to second origin.

      Default: [500, 502, 503, 504]

    • getFailoverCustomOriginSource

      @Stability(Stable) @Nullable default CustomOriginConfig getFailoverCustomOriginSource()
      A custom origin source for failover in case the s3OriginSource returns invalid status code.

      Default: - no failover configuration

    • getFailoverS3OriginSource

      @Stability(Stable) @Nullable default S3OriginConfig getFailoverS3OriginSource()
      An s3 origin source for failover in case the s3OriginSource returns invalid status code.

      Default: - no failover configuration

    • getOriginShieldRegion

      @Stability(Stable) @Nullable default String getOriginShieldRegion()
      When you enable Origin Shield in the AWS Region that has the lowest latency to your origin, you can get better network performance.

      Default: - origin shield not enabled

      See Also:
    • getS3OriginSource

      @Stability(Stable) @Nullable default S3OriginConfig getS3OriginSource()
      An s3 origin source - if you're using s3 for your assets.
    • builder

      @Stability(Stable) static SourceConfiguration.Builder builder()
      Returns:
      a SourceConfiguration.Builder of SourceConfiguration