如何将 json 存储到 aws 参数存储或从 aws 参数存储获取 json

2024-01-08

我使用 Livy REST API 提交 Spark 应用程序。

{
  “file”: <application-jar>,
  “className”: “<main-class>”,
  “args”: my_args,
  “conf”: my_conf
}

my_args = [args1, args2, ...]
my_conf = {'foo1': 'bar1', 'foo2': 'bar2'...}

我希望 my_conf (json 机密)存储在 AWS SSM 参数存储中,并在使用 Livy 的 python 脚本提交 Spark 应用程序时从参数存储中使用它。 如何在参数存储中存储和获取(在Python中获取相同的json)my_conf?


import json
import boto3

my_conf = {'foo1': 'bar1', 'foo2': 'bar2'}
boto3.client('ssm').put_parameter(Name='MyParameter', Value=json.dumps(my_conf), Type='String')
my_conf = json.loads(boto3.client('ssm').get_parameter(Name='MyParameter'))

...假设您已设置适当的权限以允许您进行这些调用。

See

  • https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.get_parameter https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.get_parameter
  • https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.get_parameter https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.put_parameter
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将 json 存储到 aws 参数存储或从 aws 参数存储获取 json 的相关文章

随机推荐