updateDistribution method
Updates the configuration for a CloudFront distribution.
The update process includes getting the current distribution
configuration, updating it to make your changes, and then submitting an
UpdateDistribution request to make the updates.
To update a web distribution using the CloudFront API
-
Use
GetDistributionConfigto get the current configuration, including the version identifier (ETag). -
Update the distribution configuration that was returned in the response.
Note the following important requirements and restrictions:
-
You must copy the
ETagfield value from the response. (You'll use it for theIfMatchparameter in your request.) Then, remove theETagfield from the distribution configuration. -
You can't change the value of
CallerReference.
-
You must copy the
-
Submit an
UpdateDistributionrequest, providing the updated distribution configuration. The new configuration replaces the existing configuration. The values that you specify in anUpdateDistributionrequest are not merged into your existing configuration. Make sure to include all fields: the ones that you modified and also the ones that you didn't.
May throw AccessDenied.
May throw CNAMEAlreadyExists.
May throw ContinuousDeploymentPolicyInUse.
May throw EntityNotFound.
May throw IllegalFieldLevelEncryptionConfigAssociationWithCacheBehavior.
May throw IllegalOriginAccessConfiguration.
May throw IllegalUpdate.
May throw InconsistentQuantities.
May throw InvalidArgument.
May throw InvalidDefaultRootObject.
May throw InvalidDomainNameForOriginAccessControl.
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 InvalidOriginAccessControl.
May throw InvalidOriginAccessIdentity.
May throw InvalidOriginKeepaliveTimeout.
May throw InvalidOriginReadTimeout.
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 NoSuchContinuousDeploymentPolicy.
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 StagingDistributionInUse.
May throw TooManyCacheBehaviors.
May throw TooManyCertificates.
May throw TooManyCookieNamesInWhiteList.
May throw TooManyDistributionCNAMEs.
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 distributionConfig :
The distribution's configuration information.
Parameter id :
The distribution's id.
Parameter ifMatch :
The value of the ETag header that you received when
retrieving the distribution's configuration. For example:
E2QWRUHAPOMQZL.
Implementation
Future<UpdateDistributionResult> updateDistribution({
required DistributionConfig distributionConfig,
required String id,
String? ifMatch,
}) async {
final headers = <String, String>{
if (ifMatch != null) 'If-Match': ifMatch.toString(),
};
final $result = await _protocol.sendRaw(
method: 'PUT',
requestUri: '/2020-05-31/distribution/${Uri.encodeComponent(id)}/config',
headers: headers,
payload: distributionConfig.toXml('DistributionConfig'),
exceptionFnMap: _exceptionFns,
);
final $elem = await _s.xmlFromResponse($result);
return UpdateDistributionResult(
distribution: Distribution.fromXml($elem),
eTag: _s.extractHeaderStringValue($result.headers, 'ETag'),
);
}