I want to get multiple parameters from the SSM parameter store at once! In that case, use get_parameters
or get_parameters_by_path
to get a good feeling.
However, I didn't know this, but it seems that I can only get up to 10 at a time, and to get it after that, I have to retry using the returned token.
Create 11 parameters in the path under / HOGE /
of SSM parameter store and experiment with lambda (python3.8).
lambda
import json
import boto3
ssm = boto3.client("ssm")
def lambda_handler(event, context):
params = dict()
responseSSM = ssm.get_parameters_by_path(
Path = "/HOGE",
WithDecryption = False
)
for param in responseSSM["Parameters"]:
params[ param["Name"] ] = param["Value"]
while True:
if not "NextToken" in responseSSM:
break
responseSSM = ssm.get_parameters_by_path(
NextToken = responseSSM["NextToken"],
Path = "/HOGE",
WithDecryption = False
)
for param in responseSSM["Parameters"]:
params[ param["Name"] ] = param["Value"]
for prm in params:
print(prm)
# params["/HOGE/FUGA1"]Etc. You can access by specifying the parameter name as it is.
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
Execute with SSMFullAccess authority granted to the IAM role.
The output is as follows. It was confirmed that 10 or more cases could be obtained. The order is. .. A mystery.
log
/HOGE/FUGA1
/HOGE/FUGA10
/HOGE/FUGA11
/HOGE/FUGA2
/HOGE/FUGA4
/HOGE/FUGA5
/HOGE/FUGA6
/HOGE/FUGA7
/HOGE/FUGA8
/HOGE/FUGA9
/HOGE/FUGA3
Recommended Posts