Created
July 18, 2021 11:54
-
-
Save remie/0933177ef1c894ebfb9e330b0d3910ac to your computer and use it in GitHub Desktop.
Using AWS Certificate Manager SDK to provision a certificate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const accessKeyId = process.env.AWS_ACCESS_KEY_ID; | |
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; | |
const acm = new ACM({ | |
credentials: async () => ({ accessKeyId, secretAccessKey }), | |
region: 'us-east-1' | |
}); | |
const { CertificateArn } = await acm.requestCertificate({ | |
DomainName: <<DOMAIN_NAME>>, | |
ValidationMethod: ValidationMethod.DNS | |
}); | |
if (CertificateArn) { | |
domain.certificateARN = CertificateArn; | |
const certificate = await acm.describeCertificate({ CertificateArn }); | |
if (certificate && certificate.Certificate) { | |
const validationDetails = certificate.Certificate.DomainValidationOptions?.find(item => item.DomainName === domain.name && item.ValidationMethod === ValidationMethod.DNS); | |
if (validationDetails && validationDetails.ResourceRecord) { | |
const { Name, Value } = validationDetails.ResourceRecord; | |
// Use Name and Value for the CNAME record | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment