Introduction

AWS Systems Manager (SSM) is a collection of capabilities that helps you automate management tasks such as collecting system inventory, applying operating system (OS) patches, automating the creation of Amazon Machine Images (AMIs), and configuring operating systems (OSs) and applications at scale.

SSM provides a Parameter Store that allows you to store configuration data and secure strings. You can store up to 10,000 parameters per region. You can store up to 4 KB of data for each parameter.

In this tutorial, we will look at how to store a file in SSM Parameter Store using AWS CLI.

How to store a value in the SSM Parameter Store?

The put-parameter command allows you to store a value in the SSM Parameter Store. The command takes the following parameters:

  • --name: The name of the parameter.
  • --value: The value of the parameter.
  • --type: The type of the parameter. The valid values are String, StringList, SecureString.
  • --overwrite: Overwrite an existing parameter. The default value is false.

The following command will store the value my-value in the parameter my-param:


aws ssm put-parameter --name my-param --value my-value --type String

How to store a file in the SSM Parameter Store?

To store the contents of a file in the SSM Parameter Store, we can use the file:// URI scheme. The following command will store the contents of the file my-file.txt in the parameter my-param:


aws ssm put-parameter --name my-param --value file://my-file.txt --type String

If we want to overwrite an existing parameter, we can use the --overwrite parameter:


aws ssm put-parameter --name my-param --value file://my-file.txt --type String --overwrite

How to filter the contents of the file before storing it in the SSM Parameter Store?

Let’s say we have a file my-file.json with the following contents:


{
    "a": "b",
    "c": {
        "d": "e"
    }
}

If we want to filter the contents of the file before storing it in the SSM Parameter Store, we can use the following command:

```bash

aws ssm put-parameter --name my-param --value $(cat my-file.json | jq -r ".c.d") --type String

Conclusion

In this tutorial, we looked at how to store a file in SSM Parameter Store using AWS CLI.