createCertificate method

Future<CreateCertificateResult> createCertificate({
  1. required String certificateName,
  2. required String domainName,
  3. List<String>? subjectAlternativeNames,
  4. List<Tag>? tags,
})

Creates an SSL/TLS certificate for a Amazon Lightsail content delivery network (CDN) distribution.

After the certificate is created, use the AttachCertificateToDistribution action to attach the certificate to your distribution.

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

Parameter certificateName : The name for the certificate.

Parameter domainName : The domain name (e.g., example.com) for the certificate.

Parameter subjectAlternativeNames : An array of strings that specify the alternate domains (e.g., example2.com) and subdomains (e.g., blog.example.com) for the certificate.

You can specify a maximum of nine alternate domains (in addition to the primary domain name).

Wildcard domain entries (e.g., *.example.com) are not supported.

Parameter tags : The tag keys and optional values to add to the certificate during create.

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

Implementation

Future<CreateCertificateResult> createCertificate({
  required String certificateName,
  required String domainName,
  List<String>? subjectAlternativeNames,
  List<Tag>? tags,
}) async {
  ArgumentError.checkNotNull(certificateName, 'certificateName');
  ArgumentError.checkNotNull(domainName, 'domainName');
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Lightsail_20161128.CreateCertificate'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'certificateName': certificateName,
      'domainName': domainName,
      if (subjectAlternativeNames != null)
        'subjectAlternativeNames': subjectAlternativeNames,
      if (tags != null) 'tags': tags,
    },
  );

  return CreateCertificateResult.fromJson(jsonResponse.body);
}