1. Answers
  2. Creating an AWS IAM Access Key

How do I build an AWS IAM access key?

In this guide, we’ll go through an example program that creates an AWS IAM user and then generates an access key for that user. Enabling programmatic access to your AWS resources is crucial for automation and integration with other services. Here are the steps to achieve this:

  1. Create an IAM User: This IAM user will be the entity you generate access keys for.
  2. Generate Access Keys: This will consist of an Access Key ID and Secret Access Key associated with the IAM user.

First, set up your configuration with AWS provider to authenticate and configure your AWS access.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create an IAM user
const example = new aws.iam.User("example", {name: "example-user"});
// Create an IAM access key for the user
const exampleAccessKey = new aws.iam.AccessKey("example", {user: example.name});
export const accessKeyId = exampleAccessKey.id;
export const secretAccessKey = exampleAccessKey.secret;

Explanation

  • provider “aws”: Sets up the AWS provider with the specified region.
  • resource “aws_iam_user” “example”: Defines an IAM user resource with the name “example-user”.
  • resource “aws_iam_access_key” “example”: Creates an access key for the specified IAM user.
  • output “access_key_id” and output “secret_access_key”: Outputs the Access Key ID and Secret Access Key which are necessary for programmatic access.

By the end of this, you have successfully created an IAM user and associated access keys, outputting the credential details securely.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up