How do I build an AWS SSM document with Pulumi?
Introduction
In this tutorial, we’ll demonstrate how to create an AWS Systems Manager (SSM) Document using Pulumi. SSM Documents define actions that Systems Manager performs on your managed instances.
What We Are Going to Do
We’ll create an SSM Document that contains a simple command to run on the instance. This document can then be used in various operations throughout AWS Systems Manager, like running commands on EC2 instances.
Steps
- Define the AWS provider to interact with the AWS resources.
- Create an SSM Document with a sample command.
- Export the created ARNs and Names as stack outputs for reference.
Program to Create AWS SSM Document
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.ssm.Document("example", {
name: "MySSMDocument",
documentType: "Command",
content: `{
"schemaVersion": "2.2",
"description": "Run a shell script or specify the paths to scripts to run.",
"mainSteps": [
{
"action": "aws:runShellScript",
"name": "runShellScript",
"inputs": {
"runCommand": [
"echo Hello, World!"
]
}
}
]
}
`,
tags: {
Name: "MySSMDocument",
},
});
export const documentName = example.name;
export const documentArn = example.arn;
Key Points
- AWS Provider: Specifies the AWS region where the resources will be created.
- SSM Document Resource: Creates an AWS Systems Manager Document with a specified content that includes a simple
runShellScript
command. - Outputs: Exports the name and ARN of the created document for easy access and future reference.
Summary
In this guide, we’ve created an AWS Systems Manager Document using Pulumi. This document contains a script that echoes “Hello, World!”. This example provides a foundation for more complex command documents you might want to create in your AWS environment.
Utilize the created document in your Systems Manager operations to automate tasks and manage your AWS resources efficiently. Happy deploying!
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.