Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
使用 Amazon SDK 上传 IAM 服务器证书
以下代码示例显示了如何上传 Amazon Identity and Access Management(IAM)服务器证书。
- 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);
};
有关 Amazon 软件开发工具包开发人员指南和代码示例的完整列表,请参阅 将 IAM 与 Amazon 开发工具包配合使用。本主题还包括有关入门的信息以及有关先前的软件开发工具包版本的详细信息。