I'm trying to store value in parameter store and to define TTL (Time To Live) for this value using C#, .NET with PutParameterRequest
.
How should I do it ?
This is how I'm saving the parameter for now with no expiration date:
var parametersStoreRequest = new PutParameterRequest()
{
Name = "Miao",
Value = "MiaoChech",
Type = ParameterType.String,
}
try
{
var parametersStoreResponse = await parameterStoreClient.PutParameterAsync(parametersStoreRequest);
}
CodePudding user response:
You can use Parameter policies to assign specific criteria to a parameter such as an expiration date or time to live. Parameter Store allows the following types of policies: Expiration
, ExpirationNotification
, and NoChangeNotification
.
The following example shows the request syntax for a PutParameter API request that assigns Expiration
to a new SecureString
parameter named Password
.
{
"Name": "Password",
"Description": "Parameter with policies",
"Value": "P@ssW*rd21",
"Type": "SecureString",
"Overwrite": "True",
"Policies": [
{
"Type": "Expiration",
"Version": "1.0",
"Attributes": {
"Timestamp": "2018-12-02T21:34:33.000Z"
}
}
]
}
So you need to pass the Policies
values as a string with One or more policies to apply to a parameter in PutParameterRequest
.
"[{policies-enclosed-in-brackets-and-curly-braces}]"
I am not familiar with the .Net but I hope this will help you to implement your requirement.
Note: The Expiration
policy deletes the parameter. You can specify a specific date and time by using either the ISO_INSTANT
format or the ISO_OFFSET_DATE_TIME
format.
The above example uses the ISO_INSTANT
format. You can also specify a date and time by using the ISO_OFFSET_DATE_TIME
format. Here is an example: 2019-11-01T22:13:48.87 10:30:00
.
Reference: PutParameter
CodePudding user response:
Solved ! Thank you @Arpit Jain for your answer :)
this is the correct format for PutParameterRequest in .net c#
var parameterStoreClient = new AmazonSimpleSystemsManagementClient(Amazon.RegionEndpoint.EUWest1);
var currentTTL = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.000Z");
var parametersStoreRequest = new PutParameterRequest()
{
Name = "Miao",
Value = "MiaoChech",
Type = ParameterType.String,
Policies= "[{'Type':'Expiration','Version':'1.0','Attributes':{'Timestamp':'" currentTTL "'}}]"
};
try
{
var parametersStoreResponse = await parameterStoreClient.PutParameterAsync(parametersStoreRequest);
}