Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Upload an IAM server certificate using an Amazon SDK
The following code example shows how to upload an Amazon Identity and Access Management (IAM) server certificate.
- JavaScript
-
- SDK for JavaScript (v3)
-
import { UploadServerCertificateCommand, IAMClient } from "@aws-sdk/client-iam";
import { readFileSync } from "fs";
import { dirnameFromMetaUrl } from "libs/utils/util-fs.js";
import * as path from "path";
const client = new IAMClient({});
/**
* The certificate body and private key were generated with the
* following command.
*
* ```
* openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
* -keyout example.key -out example.crt -subj "/CN=example.com" \
* -addext "subjectAltName=DNS:example.com,DNS:www.example.net,IP:10.0.0.1"
* ```
*/
const certBody = readFileSync(
path.join(
dirnameFromMetaUrl(import.meta.url),
"../../../../resources/sample_files/sample_cert.pem"
)
);
const privateKey = readFileSync(
path.join(
dirnameFromMetaUrl(import.meta.url),
"../../../../resources/sample_files/sample_private_key.pem"
)
);
/**
*
* @param {string} certificateName
*/
export const uploadServerCertificate = (certificateName) => {
const command = new UploadServerCertificateCommand({
ServerCertificateName: certificateName,
CertificateBody: certBody.toString(),
PrivateKey: privateKey.toString(),
});
return client.send(command);
};
For a complete list of Amazon SDK developer guides and code examples, see
Using IAM with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.