How to get all parameter name value pairs with a single call to AWS-Parameters-and-Secrets-Lambda-Extension (arn:aws:lambda:eu-west-1:015030872274:layer:AWS-Parameters-and-Secrets-Lambda-Extension:4)
i.e. Equivalent call to this AWS CLI to non Lambda Layer SSM Parameter Store:
aws ssm get-parameters-by-path --path "/service1/prod" --recursive
Instead of this piece of code (c# / .net6) where for each key a request/response is being made:
var stage = "prod";
var awsSessionToken = Environment.GetEnvironmentVariable("AWS_SESSION_TOKEN");
var request = new RestRequest(
"http://localhost:2773/systemsmanager/parameters/get",
Method.Get
)
.AddHeader("X-Aws-Parameters-Secrets-Token", awsSessionToken)
.AddQueryParameter("withDecryption", true);
Log.Information("{@Request}", request);
var keys = new string[] {
$"/service1/{stage}/key1",
$"/service1/{stage}/key2",
$"/service1/{stage}/key3",
$"/service1/{stage}/key4",
$"/service1/{stage}/key5",
$"/service1/{stage}/key6",
$"/service1/{stage}/key7",
$"/service1/{stage}/key8",
$"/service1/{stage}/key9",
$"/service1/{stage}/key10",
$"/service1/{stage}/key11",
};
foreach (var key in keys)
{
var _request = request
.AddOrUpdateParameter("name", key, ParameterType.QueryString);
var _response =
await restClient.ExecuteGetAsync<ParameterResponse>(_request);
Parameters.Add(new Parameter(_response.Data.Parameter.Name,
_response.Data.Parameter.Value
)
);
}
Please note that I can implement the flow in C#, I just can't find the specifics of the API more detailed than in here.
The
AWS-Parameters-and-Secrets-Lambda-Extensionlayer does not have the capability to retrieve SSM parameters based on apathvalue. Instead, it expects anameparameter in the query string, so you can retrieve only one record at a time based on the SSM parameter name.If you want to retrieve SSM parameters based on a
pathvalue, then you can use the following NuGet package, which enables you to retrieve multiple configuration values simultaneously from the SSM parameter store.The mentioned Amazon Systems Manager NuGet package utilizes the .NET
ConfigurationBuilderto process the configuration values from the SSM parameter store. In order to access theConfigurationBuilder, you also need to include the following NuGet packages in your lambda function.Here is a sample code snippet that shows how to retrieve configuration values from the SSM parameter store based on the
pathvalue:p.s. To retrieve configuration values by the path in your Lambda function, you should grant the following IAM role permission:
ssm:GetParametersByPath