Skip to content

create_distribution async

create_distribution(
    distribution_name: ResourceName,
    origin: InputOrigin,
    default_cache_behavior: CacheBehavior,
    bundle_id: string,
    *,
    config_overrides: Optional[AsyncLightsailClientConfig] = None,
    cache_behavior_settings: Optional[CacheSettings] = None,
    cache_behaviors: Optional[CacheBehaviorList] = None,
    ip_address_type: Optional[IpAddressType] = None,
    tags: Optional[TagList] = None,
    certificate_name: Optional[ResourceName] = None,
    viewer_minimum_tls_protocol_version: Optional[
        ViewerMinimumTlsProtocolVersionEnum
    ] = None,
    enable_private_origin_access: Optional[boolean] = None,
    default_root_object: Optional[string] = None,
    custom_error_responses: Optional[DistributionCustomErrorResponseList] = None,
) -> CreateDistributionResult

Creates an Amazon Lightsail content delivery network (CDN) distribution.

A distribution is a globally distributed network of caching servers that improve the performance of your website or web application hosted on a Lightsail instance. For more information, see Content delivery networks in Amazon Lightsail.

Parameters:

  • distribution_name (ResourceName) –

    The name for the distribution.

  • origin (InputOrigin) –

    An object that describes the origin resource for the distribution, such as a Lightsail instance, bucket, or load balancer.

    The distribution pulls, caches, and serves content from the origin.

  • default_cache_behavior (CacheBehavior) –

    An object that describes the default cache behavior for the distribution.

  • cache_behavior_settings (Optional[CacheSettings], default: None ) –

    An object that describes the cache behavior settings for the distribution.

  • cache_behaviors (Optional[CacheBehaviorList], default: None ) –

    An array of objects that describe the per-path cache behavior for the distribution.

  • bundle_id (string) –

    The bundle ID to use for the distribution.

    A distribution bundle describes the specifications of your distribution, such as the monthly cost and monthly network transfer quota.

    Use the GetDistributionBundles action to get a list of distribution bundle IDs that you can specify.

  • ip_address_type (Optional[IpAddressType], default: None ) –

    The IP address type for the distribution.

    The possible values are ipv4 for IPv4 only, and dualstack for IPv4 and IPv6.

    The default value is dualstack.

  • tags (Optional[TagList], default: None ) –

    The tag keys and optional values to add to the distribution during create.

    Use the TagResource action to tag a resource after it's created.

  • certificate_name (Optional[ResourceName], default: None ) –

    The name of the SSL/TLS certificate that you want to attach to the distribution.

    Use the GetCertificates action to get a list of certificate names that you can specify.

  • viewer_minimum_tls_protocol_version (Optional[ViewerMinimumTlsProtocolVersionEnum], default: None ) –

    The minimum TLS protocol version for the SSL/TLS certificate.

  • enable_private_origin_access (Optional[boolean], default: None ) –

    Specifies whether to enable private origin access for the distribution. With private origin access, the distribution can serve objects that aren't publicly accessible from a Lightsail bucket.

    Lightsail grants the distribution permission to read the bucket's objects. Enabling private origin access doesn't change the bucket's access settings, and you can still retrieve publicly accessible objects directly from the bucket's endpoint.

    You can enable private origin access only when the distribution's origin is a Lightsail bucket. If the origin is another resource type, the request fails.

  • default_root_object (Optional[string], default: None ) –

    The object (for example, index.html) that the distribution returns when a viewer requests the root URL of the distribution (/) instead of a specific object. The object that you specify must be available from the origin.

  • custom_error_responses (Optional[DistributionCustomErrorResponseList], default: None ) –

    An array of objects that describe the custom error responses for the distribution. With a custom error response, you can specify the page to return when the origin responds with a given HTTP error code. You can also specify the HTTP status code to send to the viewer.

Raises:

  • AccessDeniedException –

    Lightsail throws this exception when the user cannot be authenticated or uses invalid credentials to access a resource.

  • InvalidInputException –

    Lightsail throws this exception when user input does not conform to the validation rules of an input field.

    Domain and distribution APIs are only available in the N. Virginia (us-east-1) Amazon Web Services Region. Please set your Amazon Web Services Region configuration to us-east-1 to create, view, or edit these resources.

  • NotFoundException –

    Lightsail throws this exception when it cannot find a resource.

  • OperationFailureException –

    Lightsail throws this exception when an operation fails to execute.

  • ServiceException –

    A general service exception.

  • UnauthenticatedException –

    Lightsail throws this exception when the user has not been authenticated.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_lightsail/_services/async_lightsail.py
async def create_distribution(
    self,
    distribution_name: "capo_lightsail.types.resource_name.ResourceName",
    origin: "capo_lightsail.types.input_origin.InputOrigin",
    default_cache_behavior: "capo_lightsail.types.cache_behavior.CacheBehavior",
    bundle_id: "capo_lightsail.types.string.string",
    *,
    config_overrides: Optional[AsyncLightsailClientConfig] = None,
    cache_behavior_settings: Optional[
        "capo_lightsail.types.cache_settings.CacheSettings"
    ] = None,
    cache_behaviors: Optional[
        "capo_lightsail.types.cache_behavior_list.CacheBehaviorList"
    ] = None,
    ip_address_type: Optional[
        "capo_lightsail.types.ip_address_type.IpAddressType"
    ] = None,
    tags: Optional["capo_lightsail.types.tag_list.TagList"] = None,
    certificate_name: Optional[
        "capo_lightsail.types.resource_name.ResourceName"
    ] = None,
    viewer_minimum_tls_protocol_version: Optional[
        "capo_lightsail.types.viewer_minimum_tls_protocol_version_enum.ViewerMinimumTlsProtocolVersionEnum"
    ] = None,
    enable_private_origin_access: Optional[
        "capo_lightsail.types.boolean.boolean"
    ] = None,
    default_root_object: Optional["capo_lightsail.types.string.string"] = None,
    custom_error_responses: Optional[
        "capo_lightsail.types.distribution_custom_error_response_list.DistributionCustomErrorResponseList"
    ] = None,
) -> "capo_lightsail.types.create_distribution_result.CreateDistributionResult":
    """<p>Creates an Amazon Lightsail content delivery network (CDN) distribution.</p> <p>A distribution is a globally distributed network of caching servers that improve the performance of your website or web application hosted on a Lightsail instance. For more information, see <a href="https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-content-delivery-network-distributions">Content delivery networks in Amazon Lightsail</a>.</p>

    Args:
        distribution_name: <p>The name for the distribution.</p>
        origin: <p>An object that describes the origin resource for the distribution, such as a Lightsail instance, bucket, or load balancer.</p> <p>The distribution pulls, caches, and serves content from the origin.</p>
        default_cache_behavior: <p>An object that describes the default cache behavior for the distribution.</p>
        cache_behavior_settings: <p>An object that describes the cache behavior settings for the distribution.</p>
        cache_behaviors: <p>An array of objects that describe the per-path cache behavior for the distribution.</p>
        bundle_id: <p>The bundle ID to use for the distribution.</p> <p>A distribution bundle describes the specifications of your distribution, such as the monthly cost and monthly network transfer quota.</p> <p>Use the <code>GetDistributionBundles</code> action to get a list of distribution bundle IDs that you can specify.</p>
        ip_address_type: <p>The IP address type for the distribution.</p> <p>The possible values are <code>ipv4</code> for IPv4 only, and <code>dualstack</code> for IPv4 and IPv6.</p> <p>The default value is <code>dualstack</code>.</p>
        tags: <p>The tag keys and optional values to add to the distribution during create.</p> <p>Use the <code>TagResource</code> action to tag a resource after it's created.</p>
        certificate_name: <p>The name of the SSL/TLS certificate that you want to attach to the distribution.</p> <p>Use the <a href="https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetCertificates.html">GetCertificates</a> action to get a list of certificate names that you can specify.</p>
        viewer_minimum_tls_protocol_version: <p>The minimum TLS protocol version for the SSL/TLS certificate.</p>
        enable_private_origin_access: <p>Specifies whether to enable private origin access for the distribution. With private origin access, the distribution can serve objects that aren't publicly accessible from a Lightsail bucket.</p> <p>Lightsail grants the distribution permission to read the bucket's objects. Enabling private origin access doesn't change the bucket's access settings, and you can still retrieve publicly accessible objects directly from the bucket's endpoint.</p> <note> <p>You can enable private origin access only when the distribution's origin is a Lightsail bucket. If the origin is another resource type, the request fails.</p> </note>
        default_root_object: <p>The object (for example, <code>index.html</code>) that the distribution returns when a viewer requests the root URL of the distribution (<code>/</code>) instead of a specific object. The object that you specify must be available from the origin.</p>
        custom_error_responses: <p>An array of objects that describe the custom error responses for the distribution. With a custom error response, you can specify the page to return when the origin responds with a given HTTP error code. You can also specify the HTTP status code to send to the viewer.</p>

    Raises:
        capo_lightsail.errors.access_denied_exception.AccessDeniedException: <p>Lightsail throws this exception when the user cannot be authenticated or uses invalid credentials to access a resource.</p>
        capo_lightsail.errors.invalid_input_exception.InvalidInputException: <p>Lightsail throws this exception when user input does not conform to the validation rules of an input field.</p> <note> <p>Domain and distribution APIs are only available in the N. Virginia (<code>us-east-1</code>) Amazon Web Services Region. Please set your Amazon Web Services Region configuration to <code>us-east-1</code> to create, view, or edit these resources.</p> </note>
        capo_lightsail.errors.not_found_exception.NotFoundException: <p>Lightsail throws this exception when it cannot find a resource.</p>
        capo_lightsail.errors.operation_failure_exception.OperationFailureException: <p>Lightsail throws this exception when an operation fails to execute.</p>
        capo_lightsail.errors.service_exception.ServiceException: <p>A general service exception.</p>
        capo_lightsail.errors.unauthenticated_exception.UnauthenticatedException: <p>Lightsail throws this exception when the user has not been authenticated.</p>
        capo_lightsail.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_lightsail.types.create_distribution_request.CreateDistributionRequest]",
    ) -> AsyncOperationResponse[
        "capo_lightsail.types.create_distribution_result.CreateDistributionResult"
    ]:
        import capo_lightsail._operations.lightsail_20161128.create_distribution

        (
            output,
            http_response,
        ) = await capo_lightsail._operations.lightsail_20161128.create_distribution.async_create_distribution(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateDistribution")
    )
    input_: capo_lightsail.types.create_distribution_request.CreateDistributionRequest = {
        "distribution_name": distribution_name,
        "origin": origin,
        "default_cache_behavior": default_cache_behavior,
        "bundle_id": bundle_id,
    }
    if cache_behavior_settings is not None:
        input_["cache_behavior_settings"] = cache_behavior_settings
    if cache_behaviors is not None:
        input_["cache_behaviors"] = cache_behaviors
    if ip_address_type is not None:
        input_["ip_address_type"] = ip_address_type
    if tags is not None:
        input_["tags"] = tags
    if certificate_name is not None:
        input_["certificate_name"] = certificate_name
    if viewer_minimum_tls_protocol_version is not None:
        input_["viewer_minimum_tls_protocol_version"] = (
            viewer_minimum_tls_protocol_version
        )
    if enable_private_origin_access is not None:
        input_["enable_private_origin_access"] = enable_private_origin_access
    if default_root_object is not None:
        input_["default_root_object"] = default_root_object
    if custom_error_responses is not None:
        input_["custom_error_responses"] = custom_error_responses

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output