In my python script, I would like to extract certain values from AWS parameter store using STS. I have a role called ‘IAMRole’ that I can use to access this account. I have created an STS client and a session and I am able to generate the access key ID, Secret Access Key and the Session Token.
For example the parameter path is ‘/abc/xyz/ServerIP’. I want to be able to extract the Server IP in my script. Can you please help me with how to do that? I am new to python and STS. I think the problem is in the get_parameter API call I am making in the below code:
sts = boto3.client('sts', region_name='us-east-1')
assumed_role = sts.assume_role(
RoleArn='arn:aws:iam::xxxxxxxxxx:role/IAMRole',
RoleSessionName='MyScript'
)
session = boto3.session.Session(
aws_access_key_id=assumed_role['Credentials']['AccessKeyId'],
aws_secret_access_key=assumed_role['Credentials']['SecretAccessKey'],
aws_session_token=assumed_role['Credentials']['SessionToken']
)
IP= "/abc/xyz/ServerIP"
IPAddress = sts.get_parameter(Name=IP) [
"Parameter"
]["Value"]
print (IPAddress)