[PYTHON] Get 10 or more data from SSM parameter store

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

Get 10 or more data from SSM parameter store
Get structural data from CHEMBLID
[Python] Extract text data from XML data of 10GB or more.
Get data from Quandl in Python
Get data from Twitter using Tweepy
[Note] Get data from PostgreSQL with Python
Get data from Cloudant with Bluemix flask
Get data from an oscilloscope with pyVISA
Get time series data from k-db.com in Python
Get data files from elsewhere during pip install
Get data from GPS module at 10Hz in Python
How to get more than 1000 data with SQLAlchemy + MySQLdb
Get data from database via ODBC with Python (Access)