createDistribution method

Future<CreateDistributionResult> createDistribution({
  1. required String bundleId,
  2. required CacheBehavior defaultCacheBehavior,
  3. required String distributionName,
  4. required InputOrigin origin,
  5. CacheSettings? cacheBehaviorSettings,
  6. List<CacheBehaviorPerPath>? cacheBehaviors,
  7. List<Tag>? tags,
})

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.

May throw ServiceException. May throw InvalidInputException. May throw NotFoundException. May throw OperationFailureException. May throw AccessDeniedException. May throw UnauthenticatedException.

Parameter bundleId : 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.

Parameter defaultCacheBehavior : An object that describes the default cache behavior for the distribution.

Parameter distributionName : The name for the distribution.

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

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

Parameter cacheBehaviorSettings : An object that describes the cache behavior settings for the distribution.

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

Parameter tags : 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.

Implementation

Future<CreateDistributionResult> createDistribution({
  required String bundleId,
  required CacheBehavior defaultCacheBehavior,
  required String distributionName,
  required InputOrigin origin,
  CacheSettings? cacheBehaviorSettings,
  List<CacheBehaviorPerPath>? cacheBehaviors,
  List<Tag>? tags,
}) async {
  ArgumentError.checkNotNull(bundleId, 'bundleId');
  ArgumentError.checkNotNull(defaultCacheBehavior, 'defaultCacheBehavior');
  ArgumentError.checkNotNull(distributionName, 'distributionName');
  ArgumentError.checkNotNull(origin, 'origin');
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Lightsail_20161128.CreateDistribution'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'bundleId': bundleId,
      'defaultCacheBehavior': defaultCacheBehavior,
      'distributionName': distributionName,
      'origin': origin,
      if (cacheBehaviorSettings != null)
        'cacheBehaviorSettings': cacheBehaviorSettings,
      if (cacheBehaviors != null) 'cacheBehaviors': cacheBehaviors,
      if (tags != null) 'tags': tags,
    },
  );

  return CreateDistributionResult.fromJson(jsonResponse.body);
}