There are more AWS SDK examples available in the AWS Doc SDK Examples
Use PutParameter
with an AWS SDK or CLI
The following code examples show how to use PutParameter
.
- CLI
-
- AWS CLI
-
Example 1: To change a parameter value
The following
put-parameter
example changes the value of the specified parameter.aws ssm put-parameter \ --name
"MyStringParameter"
\ --type"String"
\ --value"Vici"
\ --overwriteOutput:
{ "Version": 2, "Tier": "Standard" }
For more information, see Create a Systems Manager parameter (AWS CLI), 'Managing parameter tiers <https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html>`__, and Working with parameter policies in the AWS Systems Manager User Guide.
Example 2: To create an advanced parameter
The following
put-parameter
example creates an advanced parameter.aws ssm put-parameter \ --name
"MyAdvancedParameter"
\ --description"This is an advanced parameter"
\ --value"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat [truncated]"
\ --type"String"
\ --tierAdvanced
Output:
{ "Version": 1, "Tier": "Advanced" }
For more information, see Create a Systems Manager parameter (AWS CLI), 'Managing parameter tiers <https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html>`__, and Working with parameter policies in the AWS Systems Manager User Guide.
Example 3: To convert a standard parameter to an advanced parameter
The following
put-parameter
example converts a existing standard parameter into an advanced parameter.aws ssm put-parameter \ --name
"MyConvertedParameter"
\ --value"abc123"
\ --type"String"
\ --tierAdvanced
\ --overwriteOutput:
{ "Version": 2, "Tier": "Advanced" }
For more information, see Create a Systems Manager parameter (AWS CLI), 'Managing parameter tiers <https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html>`__, and Working with parameter policies in the AWS Systems Manager User Guide.
Example 4: To create a parameter with a policy attached
The following
put-parameter
example creates an advanced parameter with a parameter policy attached.aws ssm put-parameter \ --name
"/Finance/Payroll/q2accesskey"
\ --value"P@sSwW)rd"
\ --type"SecureString"
\ --tierAdvanced
\ --policies "[{\"Type\":\"Expiration\",\"Version\":\"1.0\",\"Attributes\":{\"Timestamp\":\"2020-06-30T00:00:00.000Z\"}},{\"Type\":\"ExpirationNotification\",\"Version\":\"1.0\",\"Attributes\":{\"Before\":\"5\",\"Unit\":\"Days\"}},{\"Type\":\"NoChangeNotification\",\"Version\":\"1.0\",\"Attributes\":{\"After\":\"60\",\"Unit\":\"Days\"}}]"Output:
{ "Version": 1, "Tier": "Advanced" }
For more information, see Create a Systems Manager parameter (AWS CLI), 'Managing parameter tiers <https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html>`__, and Working with parameter policies in the AWS Systems Manager User Guide.
Example 5: To add a policy to an existing parameter
The following
put-parameter
example attaches a policy to an existing advanced parameter.aws ssm put-parameter \ --name
"/Finance/Payroll/q2accesskey"
\ --value"N3wP@sSwW)rd"
\ --type"SecureString"
\ --tierAdvanced
\ --policies "[{\"Type\":\"Expiration\",\"Version\":\"1.0\",\"Attributes\":{\"Timestamp\":\"2020-06-30T00:00:00.000Z\"}},{\"Type\":\"ExpirationNotification\",\"Version\":\"1.0\",\"Attributes\":{\"Before\":\"5\",\"Unit\":\"Days\"}},{\"Type\":\"NoChangeNotification\",\"Version\":\"1.0\",\"Attributes\":{\"After\":\"60\",\"Unit\":\"Days\"}}]" --overwriteOutput:
{ "Version": 2, "Tier": "Advanced" }
For more information, see Create a Systems Manager parameter (AWS CLI), 'Managing parameter tiers <https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html>`__, and Working with parameter policies in the AWS Systems Manager User Guide.
-
For API details, see PutParameter
in AWS CLI Command Reference.
-
- Java
-
- SDK for Java 2.x
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.ssm.SsmClient; import software.amazon.awssdk.services.ssm.model.ParameterType; import software.amazon.awssdk.services.ssm.model.PutParameterRequest; import software.amazon.awssdk.services.ssm.model.SsmException; public class PutParameter { public static void main(String[] args) { final String usage = """ Usage: <paraName> Where: paraName - The name of the parameter. paraValue - The value of the parameter. """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String paraName = args[0]; String paraValue = args[1]; Region region = Region.US_EAST_1; SsmClient ssmClient = SsmClient.builder() .region(region) .build(); putParaValue(ssmClient, paraName, paraValue); ssmClient.close(); } public static void putParaValue(SsmClient ssmClient, String paraName, String value) { try { PutParameterRequest parameterRequest = PutParameterRequest.builder() .name(paraName) .type(ParameterType.STRING) .value(value) .build(); ssmClient.putParameter(parameterRequest); System.out.println("The parameter was successfully added."); } catch (SsmException e) { System.err.println(e.getMessage()); System.exit(1); } } }
-
For API details, see PutParameter in AWS SDK for Java 2.x API Reference.
-
- PowerShell
-
- Tools for PowerShell
-
Example 1: This example creates a parameter. There is no output if the command succeeds.
Write-SSMParameter -Name "Welcome" -Type "String" -Value "helloWorld"
Example 2: This example changes a parameter. There is no output if the command succeeds.
Write-SSMParameter -Name "Welcome" -Type "String" -Value "Good day, Sunshine!" -Overwrite $true
-
For API details, see PutParameter in AWS Tools for PowerShell Cmdlet Reference.
-
- Rust
-
- SDK for Rust
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. async fn make_parameter( client: &Client, name: &str, value: &str, description: &str, ) -> Result<(), Error> { let resp = client .put_parameter() .overwrite(true) .r#type(ParameterType::String) .name(name) .value(value) .description(description) .send() .await?; println!("Success! Parameter now has version: {}", resp.version()); Ok(()) }
-
For API details, see PutParameter
in AWS SDK for Rust API reference.
-