Working with IAM Server Certificates - Amazon SDK for JavaScript
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.

The Amazon SDK for JavaScript version 3 (v3) is a rewrite of v2 with some great new features, including modular architecture. For more information, see the Amazon SDK for JavaScript v3 Developer Guide.

Working with IAM Server Certificates

JavaScript code example that applies to Node.js execution

This Node.js code example shows:

  • How to carry out basic tasks in managing server certificates for HTTPS connections.

The Scenario

To enable HTTPS connections to your website or application on Amazon, you need an SSL/TLS server certificate. To use a certificate that you obtained from an external provider with your website or application on Amazon, you must upload the certificate to IAM or import it into Amazon Certificate Manager.

In this example, a series of Node.js modules are used to handle server certificates in IAM. The Node.js modules use the SDK for JavaScript to manage server certificates using these methods of the AWS.IAM client class:

For more information about server certificates, see Working with Server Certificates in the IAM User Guide.

Prerequisite Tasks

To set up and run this example, you must first complete these tasks:

Listing Your Server Certificates

Create a Node.js module with the file name iam_listservercerts.js. Be sure to configure the SDK as previously shown. To access IAM, create an AWS.IAM service object. Call the listServerCertificates method of the AWS.IAM service object.

// Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create the IAM service object var iam = new AWS.IAM({apiVersion: '2010-05-08'}); iam.listServerCertificates({}, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } });

To run the example, type the following at the command line.

node iam_listservercerts.js

This sample code can be found here on GitHub.

Getting a Server Certificate

Create a Node.js module with the file name iam_getservercert.js. Be sure to configure the SDK as previously shown. To access IAM, create an AWS.IAM service object. Create a JSON object containing the parameters needed get a certificate, which consists of the name of the server certificate you want. Call the getServerCertificates method of the AWS.IAM service object.

// Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create the IAM service object var iam = new AWS.IAM({apiVersion: '2010-05-08'}); iam.getServerCertificate({ServerCertificateName: 'CERTIFICATE_NAME'}, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } });

To run the example, type the following at the command line.

node iam_getservercert.js

This sample code can be found here on GitHub.

Updating a Server Certificate

Create a Node.js module with the file name iam_updateservercert.js. Be sure to configure the SDK as previously shown. To access IAM, create an AWS.IAM service object. Create a JSON object containing the parameters needed to update a certificate, which consists of the name of the existing server certificate as well as the name of the new certificate. Call the updateServerCertificate method of the AWS.IAM service object.

// Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create the IAM service object var iam = new AWS.IAM({apiVersion: '2010-05-08'}); var params = { ServerCertificateName: 'CERTIFICATE_NAME', NewServerCertificateName: 'NEW_CERTIFICATE_NAME' }; iam.updateServerCertificate(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } });

To run the example, type the following at the command line.

node iam_updateservercert.js

This sample code can be found here on GitHub.

Deleting a Server Certificate

Create a Node.js module with the file name iam_deleteservercert.js. Be sure to configure the SDK as previously shown. To access IAM, create an AWS.IAM service object. Create a JSON object containing the parameters needed to delete a server certificate, which consists of the name of the certificate you want to delete. Call the deleteServerCertificates method of the AWS.IAM service object.

// Load the AWS SDK for Node.js var AWS = require('aws-sdk'); // Set the region AWS.config.update({region: 'REGION'}); // Create the IAM service object var iam = new AWS.IAM({apiVersion: '2010-05-08'}); iam.deleteServerCertificate({ServerCertificateName: 'CERTIFICATE_NAME'}, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } });

To run the example, type the following at the command line.

node iam_deleteservercert.js

This sample code can be found here on GitHub.