copyDistribution method

Future<CopyDistributionResult> copyDistribution({
  1. required String callerReference,
  2. required String primaryDistributionId,
  3. bool? enabled,
  4. String? ifMatch,
  5. bool? staging,
})

Creates a staging distribution using the configuration of the provided primary distribution. A staging distribution is a copy of an existing distribution (called the primary distribution) that you can use in a continuous deployment workflow.

After you create a staging distribution, you can use UpdateDistribution to modify the staging distribution's configuration. Then you can use CreateContinuousDeploymentPolicy to incrementally move traffic to the staging distribution.

This API operation requires the following IAM permissions:

May throw AccessDenied. May throw CNAMEAlreadyExists. May throw DistributionAlreadyExists. May throw IllegalFieldLevelEncryptionConfigAssociationWithCacheBehavior. May throw InconsistentQuantities. May throw InvalidArgument. May throw InvalidDefaultRootObject. May throw InvalidErrorCode. May throw InvalidForwardCookies. May throw InvalidFunctionAssociation. May throw InvalidGeoRestrictionParameter. May throw InvalidHeadersForS3Origin. May throw InvalidIfMatchVersion. May throw InvalidLambdaFunctionAssociation. May throw InvalidLocationCode. May throw InvalidMinimumProtocolVersion. May throw InvalidOrigin. May throw InvalidOriginAccessControl. May throw InvalidOriginAccessIdentity. May throw InvalidOriginKeepaliveTimeout. May throw InvalidOriginReadTimeout. May throw InvalidProtocolSettings. May throw InvalidQueryStringParameters. May throw InvalidRelativePath. May throw InvalidRequiredProtocol. May throw InvalidResponseCode. May throw InvalidTTLOrder. May throw InvalidViewerCertificate. May throw InvalidWebACLId. May throw MissingBody. May throw NoSuchCachePolicy. May throw NoSuchDistribution. May throw NoSuchFieldLevelEncryptionConfig. May throw NoSuchOrigin. May throw NoSuchOriginRequestPolicy. May throw NoSuchRealtimeLogConfig. May throw NoSuchResponseHeadersPolicy. May throw PreconditionFailed. May throw RealtimeLogConfigOwnerMismatch. May throw TooManyCacheBehaviors. May throw TooManyCertificates. May throw TooManyCookieNamesInWhiteList. May throw TooManyDistributionCNAMEs. May throw TooManyDistributions. May throw TooManyDistributionsAssociatedToCachePolicy. May throw TooManyDistributionsAssociatedToFieldLevelEncryptionConfig. May throw TooManyDistributionsAssociatedToKeyGroup. May throw TooManyDistributionsAssociatedToOriginAccessControl. May throw TooManyDistributionsAssociatedToOriginRequestPolicy. May throw TooManyDistributionsAssociatedToResponseHeadersPolicy. May throw TooManyDistributionsWithFunctionAssociations. May throw TooManyDistributionsWithLambdaAssociations. May throw TooManyDistributionsWithSingleFunctionARN. May throw TooManyFunctionAssociations. May throw TooManyHeadersInForwardedValues. May throw TooManyKeyGroupsAssociatedToDistribution. May throw TooManyLambdaFunctionAssociations. May throw TooManyOriginCustomHeaders. May throw TooManyOriginGroupsPerDistribution. May throw TooManyOrigins. May throw TooManyQueryStringParameters. May throw TooManyTrustedSigners. May throw TrustedKeyGroupDoesNotExist. May throw TrustedSignerDoesNotExist.

Parameter callerReference : A value that uniquely identifies a request to create a resource. This helps to prevent CloudFront from creating a duplicate resource if you accidentally resubmit an identical request.

Parameter primaryDistributionId : The identifier of the primary distribution whose configuration you are copying. To get a distribution ID, use ListDistributions.

Parameter enabled : A Boolean flag to specify the state of the staging distribution when it's created. When you set this value to True, the staging distribution is enabled. When you set this value to False, the staging distribution is disabled.

If you omit this field, the default value is True.

Parameter ifMatch : The version identifier of the primary distribution whose configuration you are copying. This is the ETag value returned in the response to GetDistribution and GetDistributionConfig.

Parameter staging : The type of distribution that your primary distribution will be copied to. The only valid value is True, indicating that you are copying to a staging distribution.

Implementation

Future<CopyDistributionResult> copyDistribution({
  required String callerReference,
  required String primaryDistributionId,
  bool? enabled,
  String? ifMatch,
  bool? staging,
}) async {
  final headers = <String, String>{
    if (ifMatch != null) 'If-Match': ifMatch.toString(),
    if (staging != null) 'Staging': staging.toString(),
  };
  final $result = await _protocol.sendRaw(
    method: 'POST',
    requestUri:
        '/2020-05-31/distribution/${Uri.encodeComponent(primaryDistributionId)}/copy',
    headers: headers,
    payload: CopyDistributionRequest(
            callerReference: callerReference,
            primaryDistributionId: primaryDistributionId,
            enabled: enabled,
            ifMatch: ifMatch,
            staging: staging)
        .toXml('CopyDistributionRequest'),
    exceptionFnMap: _exceptionFns,
  );
  final $elem = await _s.xmlFromResponse($result);
  return CopyDistributionResult(
    distribution: Distribution.fromXml($elem),
    eTag: _s.extractHeaderStringValue($result.headers, 'ETag'),
    location: _s.extractHeaderStringValue($result.headers, 'Location'),
  );
}