Cloud.Certificate
A TLS certificate for the https services of Better Stack Cloud load
balancers (a load balancer service’s certificateIds). Either upload a
certificate and its key (certificateType: "uploaded", the API’s
default), or let Better Stack issue and renew one with Let’s Encrypt
(certificateType: "managed" with domainNames, no wildcards). A
certificate works in every availability zone. Certificates are free.
name and metadata change in place. certificateType, domainNames,
certificate, privateKey, teamId and availabilityZone replace the
certificate (the new one is created before the old one is deleted, so a
load balancer can move over). privateKey is write-only: the API never
returns it, so it is compared against the previous config, never
against the live object, and it is not in the attributes. Pass it as
Redacted so it stays out of logs and plans. Removing metadata keeps
the tags; set metadata: {} to clear them.
Creating a managed certificate does not wait for it to be issued:
issuing needs the domains to point at your load balancer, so it starts
pending and becomes issued once Let’s Encrypt validates the domains
(failed with a statusMessage otherwise; Better Stack retries daily).
An uploaded certificate is issued right away.
Uploading a certificate
Section titled “Uploading a certificate”PEM chain and key from the environment
const cert = yield* BetterStack.Cloud.Certificate("web", { certificateType: "uploaded", certificate: process.env.TLS_CERT_PEM ?? "", privateKey: Redacted.make(process.env.TLS_KEY_PEM ?? ""),});Issuing with Let’s Encrypt
Section titled “Issuing with Let’s Encrypt”A managed certificate for two domains
yield* BetterStack.Cloud.Certificate("site", { name: "site", certificateType: "managed", domainNames: ["example.com", "www.example.com"], metadata: { env: "prod" },});Looking up an existing certificate
Section titled “Looking up an existing certificate”Reference a certificate by name
const existing = BetterStack.Cloud.Certificate.lookup({ name: "site" });availabilityZone string
Availability zone the resource lives in, such as us-west-2a. Defaults to the credentials' zone (BETTERSTACK_AVAILABILITY_ZONE, or the profile's). Changing it replaces the resource. A child of a resource in another zone (a firewall rule, a node pool, a snapshot of an instance outside the credentials' zone) must repeat the parent's availabilityZone: it receives only the parent's id, so its zone cannot be derived.
certificate string
The certificate chain in PEM format, with the certificate first. An uploaded certificate requires it. A managed certificate has none until we issue it.
certificateType "uploaded" | "managed" | string
Whether you upload the certificate or we issue it. - uploaded: You upload the certificate. Send certificate and private_key. - managed: We issue and renew the certificate with Let's Encrypt. Send domain_names.
domainNames string[]
The domains the certificate covers, from 1 to 100. A managed certificate requires domain names, and wildcard domains aren't allowed. For an uploaded certificate, we read the domains from the certificate.
metadata CreateCertificateRequestMetadataMap
Your own tags, as string keys and values, at most 10. An update replaces all tags.
name string
The certificate's name. Defaults to a unique name generated from the stack, stage and logical id. Changes in place.
privateKey string | Redacted<string>
The certificate's private key in PEM format, without a passphrase. An uploaded certificate requires a private key. The key isn't returned after it's saved.
teamId string
Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.
Attributes
Section titled “Attributes”availabilityZone string always set
Availability zone the resource lives in, such as us-west-2a.
id string always set
The certificate's ID, a UUID.
certificate string | null
The certificate chain in PEM format, with the certificate first. An uploaded certificate requires it. A managed certificate has none until we issue it.
certificateType "uploaded" | "managed"
Whether you upload the certificate or we issue it. - uploaded: You upload the certificate. Send certificate and private_key. - managed: We issue and renew the certificate with Let's Encrypt. Send domain_names.
createdAt string
When the certificate was created.
domainNames string[]
The domains the certificate covers, from 1 to 100. A managed certificate requires domain names, and wildcard domains aren't allowed. For an uploaded certificate, we read the domains from the certificate.
fingerprint string | null
The certificate's SHA-256 fingerprint.
lastIssuedAt string | null
When we last issued or renewed a managed certificate, always null for an uploaded certificate.
metadata CertificateMetadataMap
Your own tags, as string keys and values, at most 10. An update replaces all tags.
name string
The certificate's name.
notValidAfter string | null
When the certificate expires.
notValidBefore string | null
When the certificate becomes valid.
status string
Whether the certificate is ready. - pending: We haven't issued the certificate yet. - issued: The certificate is ready. An uploaded certificate starts in this state. - failed: We couldn't issue the certificate. status_message says why, and we try again every day.
statusMessage string | null
Why the certificate isn't issued yet, or why issuing it failed.
teamId string
The ID of the team that owns the certificate. betterstack team list shows it.
updatedAt string
When the certificate was last changed.
Lookup
Section titled “Lookup”Certificate.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.
availabilityZone string
Zone to look in, such as us-west-2a. Certificates work in every zone. Defaults to the credentials' zone.
See also
Section titled “See also”- Ownership. Every object the stack creates carries an
alchemyentry in itsmetadata(<stack>/<stage>/<resource id>#<instance>), added on every write and left out of the attributes and of diffs; your own keys are untouched (it takes one of the 10 slots). A deploy that lost track of an object it created (a create that failed or was interrupted after the API accepted it) finds it by that marker and converges it instead of creating another;list(and soalchemy nuke) returns only Alchemy-created objects; an object that matches but carries no marker of this resource is taken over only with--adopt. - https://betterstack.com/docs/cloud/api/certificates/create-certificate/