public string CreateDistribution(string bucketName, bool enabled) { CloudFrontDistributionConfig config = new CloudFrontDistributionConfig(); config.WithOrigin(bucketName) .WithEnabled(enabled); CreateDistributionRequest request = new CreateDistributionRequest(); request.WithDistributionConfig(config); CreateDistributionResponse response = _client.CreateDistribution(request); return response.Distribution.DomainName; }
protected override void ProcessRecord() { AmazonCloudFront client = base.GetClient(); Amazon.CloudFront.Model.CreateDistributionRequest request = new Amazon.CloudFront.Model.CreateDistributionRequest(); request.Id = this._Id; request.ETag = this._ETag; request.Marker = this._Marker; request.MaxItems = this._MaxItems; Amazon.CloudFront.Model.CreateDistributionResponse response = client.CreateDistribution(request); WriteObject(response.Distribution); }
/// <summary> /// Initiates the asynchronous execution of the CreateDistribution operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateDistribution operation on AmazonCloudFrontClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndCreateDistribution /// operation.</returns> public IAsyncResult BeginCreateDistribution(CreateDistributionRequest request, AsyncCallback callback, object state) { var marshaller = new CreateDistributionRequestMarshaller(); var unmarshaller = CreateDistributionResponseUnmarshaller.Instance; return BeginInvoke<CreateDistributionRequest>(request, marshaller, unmarshaller, callback, state); }
/// <summary> /// Create a new distribution. /// </summary> /// <param name="request">Container for the necessary parameters to execute the CreateDistribution service method.</param> /// /// <returns>The response from the CreateDistribution service method, as returned by CloudFront.</returns> /// <exception cref="Amazon.CloudFront.Model.AccessDeniedException"> /// Access denied. /// </exception> /// <exception cref="Amazon.CloudFront.Model.CNAMEAlreadyExistsException"> /// /// </exception> /// <exception cref="Amazon.CloudFront.Model.DistributionAlreadyExistsException"> /// The caller reference you attempted to create the distribution with is associated with /// another distribution. /// </exception> /// <exception cref="Amazon.CloudFront.Model.InconsistentQuantitiesException"> /// The value of Quantity and the size of Items do not match. /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidArgumentException"> /// The argument is invalid. /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidDefaultRootObjectException"> /// The default root object file name is too big or contains an invalid character. /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidErrorCodeException"> /// /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidForwardCookiesException"> /// Your request contains forward cookies option which doesn't match with the expectation /// for the whitelisted list of cookie names. Either list of cookie names has been specified /// when not allowed or list of cookie names is missing when expected. /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidGeoRestrictionParameterException"> /// /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidHeadersForS3OriginException"> /// /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidLocationCodeException"> /// /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidMinimumProtocolVersionException"> /// /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidOriginAccessIdentityException"> /// The origin access identity is not valid or doesn't exist. /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidOriginException"> /// The Amazon S3 origin server specified does not refer to a valid Amazon S3 bucket. /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidProtocolSettingsException"> /// You cannot specify SSLv3 as the minimum protocol version if you only want to support /// only clients that Support Server Name Indication (SNI). /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidRelativePathException"> /// The relative path is too big, is not URL-encoded, or does not begin with a slash (/). /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidRequiredProtocolException"> /// This operation requires the HTTPS protocol. Ensure that you specify the HTTPS protocol /// in your request, or omit the RequiredProtocols element from your distribution configuration. /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidResponseCodeException"> /// /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidTTLOrderException"> /// /// </exception> /// <exception cref="Amazon.CloudFront.Model.InvalidViewerCertificateException"> /// /// </exception> /// <exception cref="Amazon.CloudFront.Model.MissingBodyException"> /// This operation requires a body. Ensure that the body is present and the Content-Type /// header is set. /// </exception> /// <exception cref="Amazon.CloudFront.Model.NoSuchOriginException"> /// No origin exists with the specified Origin Id. /// </exception> /// <exception cref="Amazon.CloudFront.Model.TooManyCacheBehaviorsException"> /// You cannot create anymore cache behaviors for the distribution. /// </exception> /// <exception cref="Amazon.CloudFront.Model.TooManyCertificatesException"> /// You cannot create anymore custom ssl certificates. /// </exception> /// <exception cref="Amazon.CloudFront.Model.TooManyCookieNamesInWhiteListException"> /// Your request contains more cookie names in the whitelist than are allowed per cache /// behavior. /// </exception> /// <exception cref="Amazon.CloudFront.Model.TooManyDistributionCNAMEsException"> /// Your request contains more CNAMEs than are allowed per distribution. /// </exception> /// <exception cref="Amazon.CloudFront.Model.TooManyDistributionsException"> /// Processing your request would cause you to exceed the maximum number of distributions /// allowed. /// </exception> /// <exception cref="Amazon.CloudFront.Model.TooManyHeadersInForwardedValuesException"> /// /// </exception> /// <exception cref="Amazon.CloudFront.Model.TooManyOriginsException"> /// You cannot create anymore origins for the distribution. /// </exception> /// <exception cref="Amazon.CloudFront.Model.TooManyTrustedSignersException"> /// Your request contains more trusted signers than are allowed per distribution. /// </exception> /// <exception cref="Amazon.CloudFront.Model.TrustedSignerDoesNotExistException"> /// One or more of your trusted signers do not exist. /// </exception> public CreateDistributionResponse CreateDistribution(CreateDistributionRequest request) { var marshaller = new CreateDistributionRequestMarshaller(); var unmarshaller = CreateDistributionResponseUnmarshaller.Instance; return Invoke<CreateDistributionRequest,CreateDistributionResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the CreateDistribution operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateDistribution operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<CreateDistributionResponse> CreateDistributionAsync(CreateDistributionRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new CreateDistributionRequestMarshaller(); var unmarshaller = CreateDistributionResponseUnmarshaller.Instance; return InvokeAsync<CreateDistributionRequest,CreateDistributionResponse>(request, marshaller, unmarshaller, cancellationToken); }
/// <summary> /// Create a new distribution. /// </summary> /// <param name="request">Container for the necessary parameters to execute the CreateDistribution service method.</param> /// /// <returns>The response from the CreateDistribution service method, as returned by CloudFront.</returns> /// <exception cref="AccessDeniedException"> /// Access denied. /// </exception> /// <exception cref="CNAMEAlreadyExistsException"> /// /// </exception> /// <exception cref="DistributionAlreadyExistsException"> /// The caller reference you attempted to create the distribution with is associated with /// another distribution. /// </exception> /// <exception cref="InconsistentQuantitiesException"> /// The value of Quantity and the size of Items do not match. /// </exception> /// <exception cref="InvalidArgumentException"> /// The argument is invalid. /// </exception> /// <exception cref="InvalidDefaultRootObjectException"> /// The default root object file name is too big or contains an invalid character. /// </exception> /// <exception cref="InvalidErrorCodeException"> /// /// </exception> /// <exception cref="InvalidForwardCookiesException"> /// Your request contains forward cookies option which doesn't match with the expectation /// for the whitelisted list of cookie names. Either list of cookie names has been /// specified when not allowed or list of cookie names is missing when expected. /// </exception> /// <exception cref="InvalidGeoRestrictionParameterException"> /// /// </exception> /// <exception cref="InvalidHeadersForS3OriginException"> /// /// </exception> /// <exception cref="InvalidLocationCodeException"> /// /// </exception> /// <exception cref="InvalidOriginAccessIdentityException"> /// The origin access identity is not valid or doesn't exist. /// </exception> /// <exception cref="InvalidOriginException"> /// The Amazon S3 origin server specified does not refer to a valid Amazon S3 bucket. /// </exception> /// <exception cref="InvalidRelativePathException"> /// The relative path is too big, is not URL-encoded, or does not begin with a slash /// (/). /// </exception> /// <exception cref="InvalidRequiredProtocolException"> /// This operation requires the HTTPS protocol. Ensure that you specify the HTTPS protocol /// in your request, or omit the RequiredProtocols element from your distribution configuration. /// </exception> /// <exception cref="InvalidResponseCodeException"> /// /// </exception> /// <exception cref="InvalidViewerCertificateException"> /// /// </exception> /// <exception cref="MissingBodyException"> /// This operation requires a body. Ensure that the body is present and the Content-Type /// header is set. /// </exception> /// <exception cref="NoSuchOriginException"> /// No origin exists with the specified Origin Id. /// </exception> /// <exception cref="TooManyCacheBehaviorsException"> /// You cannot create anymore cache behaviors for the distribution. /// </exception> /// <exception cref="TooManyCertificatesException"> /// You cannot create anymore custom ssl certificates. /// </exception> /// <exception cref="TooManyCookieNamesInWhiteListException"> /// Your request contains more cookie names in the whitelist than are allowed per cache /// behavior. /// </exception> /// <exception cref="TooManyDistributionCNAMEsException"> /// Your request contains more CNAMEs than are allowed per distribution. /// </exception> /// <exception cref="TooManyDistributionsException"> /// Processing your request would cause you to exceed the maximum number of distributions /// allowed. /// </exception> /// <exception cref="TooManyHeadersInForwardedValuesException"> /// /// </exception> /// <exception cref="TooManyOriginsException"> /// You cannot create anymore origins for the distribution. /// </exception> /// <exception cref="TooManyTrustedSignersException"> /// Your request contains more trusted signers than are allowed per distribution. /// </exception> /// <exception cref="TrustedSignerDoesNotExistException"> /// One or more of your trusted signers do not exist. /// </exception> public CreateDistributionResponse CreateDistribution(CreateDistributionRequest request) { var task = CreateDistributionAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// <para> Create a new distribution. </para> /// </summary> /// /// <param name="createDistributionRequest">Container for the necessary parameters to execute the CreateDistribution service method on /// AmazonCloudFront.</param> /// /// <returns>The response from the CreateDistribution service method, as returned by AmazonCloudFront.</returns> /// /// <exception cref="TooManyCookieNamesInWhiteListException"/> /// <exception cref="InvalidDefaultRootObjectException"/> /// <exception cref="InvalidResponseCodeException"/> /// <exception cref="MissingBodyException"/> /// <exception cref="TooManyDistributionCNAMEsException"/> /// <exception cref="InvalidForwardCookiesException"/> /// <exception cref="TooManyDistributionsException"/> /// <exception cref="NoSuchOriginException"/> /// <exception cref="InconsistentQuantitiesException"/> /// <exception cref="InvalidArgumentException"/> /// <exception cref="CNAMEAlreadyExistsException"/> /// <exception cref="TrustedSignerDoesNotExistException"/> /// <exception cref="InvalidOriginAccessIdentityException"/> /// <exception cref="InvalidOriginException"/> /// <exception cref="TooManyCertificatesException"/> /// <exception cref="InvalidRelativePathException"/> /// <exception cref="TooManyCacheBehaviorsException"/> /// <exception cref="TooManyTrustedSignersException"/> /// <exception cref="InvalidErrorCodeException"/> /// <exception cref="InvalidViewerCertificateException"/> /// <exception cref="AccessDeniedException"/> /// <exception cref="TooManyOriginsException"/> /// <exception cref="DistributionAlreadyExistsException"/> /// <exception cref="InvalidRequiredProtocolException"/> public CreateDistributionResponse CreateDistribution(CreateDistributionRequest createDistributionRequest) { IAsyncResult asyncResult = invokeCreateDistribution(createDistributionRequest, null, null, true); return EndCreateDistribution(asyncResult); }
/// <summary> /// Initiates the asynchronous execution of the CreateDistribution operation. /// <seealso cref="Amazon.CloudFront.AmazonCloudFront.CreateDistribution"/> /// </summary> /// /// <param name="createDistributionRequest">Container for the necessary parameters to execute the CreateDistribution operation on /// AmazonCloudFront.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking /// EndCreateDistribution operation.</returns> public IAsyncResult BeginCreateDistribution(CreateDistributionRequest createDistributionRequest, AsyncCallback callback, object state) { return invokeCreateDistribution(createDistributionRequest, callback, state, false); }
IAsyncResult invokeCreateDistribution(CreateDistributionRequest createDistributionRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new CreateDistributionRequestMarshaller().Marshall(createDistributionRequest); var unmarshaller = CreateDistributionResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// <para> Create a new distribution. </para> /// </summary> /// /// <param name="createDistributionRequest">Container for the necessary parameters to execute the CreateDistribution service method on /// AmazonCloudFront.</param> /// /// <returns>The response from the CreateDistribution service method, as returned by AmazonCloudFront.</returns> /// /// <exception cref="T:Amazon.CloudFront.Model.TooManyCookieNamesInWhiteListException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidGeoRestrictionParameterException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidResponseCodeException" /> /// <exception cref="T:Amazon.CloudFront.Model.MissingBodyException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidLocationCodeException" /> /// <exception cref="T:Amazon.CloudFront.Model.TooManyDistributionCNAMEsException" /> /// <exception cref="T:Amazon.CloudFront.Model.TooManyDistributionsException" /> /// <exception cref="T:Amazon.CloudFront.Model.NoSuchOriginException" /> /// <exception cref="T:Amazon.CloudFront.Model.InconsistentQuantitiesException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidArgumentException" /> /// <exception cref="T:Amazon.CloudFront.Model.CNAMEAlreadyExistsException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidOriginAccessIdentityException" /> /// <exception cref="T:Amazon.CloudFront.Model.TooManyCacheBehaviorsException" /> /// <exception cref="T:Amazon.CloudFront.Model.TooManyTrustedSignersException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidViewerCertificateException" /> /// <exception cref="T:Amazon.CloudFront.Model.TooManyOriginsException" /> /// <exception cref="T:Amazon.CloudFront.Model.DistributionAlreadyExistsException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidRequiredProtocolException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidDefaultRootObjectException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidForwardCookiesException" /> /// <exception cref="T:Amazon.CloudFront.Model.TrustedSignerDoesNotExistException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidOriginException" /> /// <exception cref="T:Amazon.CloudFront.Model.TooManyCertificatesException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidRelativePathException" /> /// <exception cref="T:Amazon.CloudFront.Model.InvalidErrorCodeException" /> /// <exception cref="T:Amazon.CloudFront.Model.AccessDeniedException" /> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public Task<CreateDistributionResponse> CreateDistributionAsync(CreateDistributionRequest createDistributionRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new CreateDistributionRequestMarshaller(); var unmarshaller = CreateDistributionResponseUnmarshaller.GetInstance(); return Invoke<IRequest, CreateDistributionRequest, CreateDistributionResponse>(createDistributionRequest, marshaller, unmarshaller, signer, cancellationToken); }
internal CreateDistributionResponse CreateDistribution(CreateDistributionRequest request) { var task = CreateDistributionAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
IAsyncResult invokeCreateDistribution(CreateDistributionRequest request, AsyncCallback callback, object state, bool synchronized) { var marshaller = new CreateDistributionRequestMarshaller(); var unmarshaller = CreateDistributionResponseUnmarshaller.Instance; return Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer); }
private async Task<CloudFrontSetting> CreateCloudFrontDistributionAsync(string bucketName, bool shouldCache = true) { using ( var client = new AmazonCloudFrontClient(cfConfigurationProvider.AccessKey, cfConfigurationProvider.SecretKey, cfConfigurationProvider.RegionEndpoint)) { var originId = $"S3-{bucketName}"; var distrubtions = await client.ListDistributionsAsync(); var existingDist = distrubtions.DistributionList.Items.SingleOrDefault( summary => summary.Origins.Items.Any(origin => origin.Id == originId)); if (existingDist != null) { return new CloudFrontSetting {BucketName = bucketName, DomainName = existingDist.DomainName}; } var distributionConfig = new DistributionConfig { CallerReference = bucketName, Enabled = true, Comment = string.Empty, Origins = new Origins { Items = { new Origin { Id = originId, DomainName = string.Format("{0}.s3.amazonaws.com", bucketName), S3OriginConfig = new S3OriginConfig {OriginAccessIdentity = string.Empty} } }, Quantity = 1 }, DefaultCacheBehavior = new DefaultCacheBehavior { AllowedMethods = new AllowedMethods {Items = {"HEAD", "GET"}, Quantity = 2}, ForwardedValues = new ForwardedValues { Headers = new Headers { Items = { "Access-Control-Request-Headers", "Access-Control-Request-Method", "Origin" }, Quantity = 3 }, QueryString = true, Cookies = new CookiePreference {Forward = new ItemSelection("none")} }, TrustedSigners = new TrustedSigners {Enabled = false, Quantity = 0}, MinTTL = 0, MaxTTL = 31536000, DefaultTTL = shouldCache ? 86400 : 0, TargetOriginId = string.Format("S3-{0}", bucketName), ViewerProtocolPolicy = new ViewerProtocolPolicy("allow-all"), }, PriceClass = PriceClass.PriceClass_All }; var request = new CreateDistributionRequest(distributionConfig); var response = await client.CreateDistributionAsync(request); return new CloudFrontSetting { BucketName = response.Distribution.DistributionConfig.CallerReference, DomainName = response.Distribution.DomainName }; } }
/// <summary> /// Initiates the asynchronous execution of the CreateDistribution operation. /// <seealso cref="Amazon.CloudFront.IAmazonCloudFront.CreateDistribution"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateDistribution operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public async Task<CreateDistributionResponse> CreateDistributionAsync(CreateDistributionRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new CreateDistributionRequestMarshaller(); var unmarshaller = CreateDistributionResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, CreateDistributionRequest, CreateDistributionResponse>(request, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }