一个python库,其中包含使用aws无服务器应用程序存储库的方便帮助程序。
serverlessrepo的Python项目详细描述
aws无服务器应用程序存储库-python
使用AWS Serverless Application Repository的带有方便帮助程序的python库。
安装
只需使用pip安装库:
pip install serverlessrepo
基本用法
serverlessrepo模块为发布应用程序和管理应用程序权限提供了一个简单的界面。要开始,请导入serverlessrepo模块:
importserverlessrepo
发布应用程序
发布应用程序(模板,sar_client=None)
给定一个AWS Serverless Application Model (SAM)模板,它使用AWS无服务器应用程序存储库中指定的元数据发布一个新应用程序如果应用程序已经存在,它将更新应用程序的元数据并在模板中指定一个新版本。
例如:
importboto3importyamlfromserverlessrepoimportpublish_applicationsar_client=boto3.client('serverlessrepo',region_name='us-east-1')withopen('template.yaml','r')asf:template=f.read()# if sar_client is not provided, we will initiate the client using region inferred from aws configurationsoutput=publish_application(template,sar_client)# Alternatively, pass parsed template as a dictionarytemplate_dict=yaml.loads(template)output=publish_application(template_dict,sar_client)
publish_application
的输出具有以下结构:
{ 'application_id': 'arn:aws:serverlessrepo:us-east-1:123456789012:applications/test-app', 'actions': ['CREATE_APPLICATION'], 'details': { 'Author': 'user1', 'Description': 'hello', 'Name': 'hello-world', 'SemanticVersion': '0.0.1', 'SourceCodeUrl': 'https://github.com/hello'} } }
actions
字段有三个可能的值:
['CREATE_APPLICATION']
-创建了一个新应用程序。
更新现有应用程序的元数据。- ^ {CD5}}更新现有应用程序的元数据并创建新版本,仅在输入模板中提供新的语义版本时才适用。
details
根据所取的actions
具有不同的含义:
- 如果创建了一个新应用程序,它将显示用于创建该应用程序的元数据值。
- 如果应用程序被更新,它将显示更新的元数据值。
- 如果更新了应用程序并创建了新版本,则它将显示更新的元数据值以及新版本号。
更新应用程序元数据(模板,应用程序id,sar_client=none)
从sam模板分析应用程序元数据,并仅更新元数据。
例如:
importboto3importyamlfromserverlessrepoimportupdate_application_metadatasar_client=boto3.client('serverlessrepo',region_name='us-east-1')withopen('template.yaml','r')asf:template=f.read()application_id='arn:aws:serverlessrepo:us-east-1:123456789012:applications/test-app'# if sar_client is not provided, we will initiate the client using region inferred from aws configurationsupdate_application_metadata(template,application_id,sar_client)# Alternatively, pass parsed template as a dictionarytemplate_dict=yaml.loads(template)update_application_metadata(template_dict,application_id,sar_client)
管理应用程序权限
公开应用程序(应用程序id,sar_client=none)
使应用程序公开,以便每个人都可以看到它
将应用程序设为私有(应用程序id,sar_client=none)
使应用程序成为私有的,以便它只对所有者可见。
与帐户共享应用程序(应用程序id、帐户id、sar客户端=无)
与指定的AWS帐户共享应用程序。
示例
importboto3fromserverlessrepoimport(make_application_public,make_application_private,share_application_with_accounts)application_id='arn:aws:serverlessrepo:us-east-1:123456789012:applications/test-app'sar_client=boto3.client('serverlessrepo',region_name='us-east-1')# Share an application publiclymake_application_public(application_id,sar_client)# Make an application privatemake_application_private(application_id,sar_client)# Share an application with other AWS accountsshare_application_with_accounts(application_id,['123456789013','123456789014'],sar_client)
开发
- 分叉存储库,然后克隆到本地:
git clone https://github.com/<username>/aws-serverlessrepo-python.git
- 设置环境:
make init
- 安装新程序包:
pipenv install [package names]
- pipenv将自动为您更新Pipfile和Pipfile.lock。
- 如果此库的使用者需要新的依赖项,请将其添加到setup.pyinstall\u requires中
- 确认一切正常:
make build
- 您可以单独运行
make test
来验证测试是否通过。 - 使用
make flake
和make lint
检查代码样式
- 您可以单独运行
- 进行代码更改,在发送请求之前再次运行所有验证:
make pr
许可证
此库是根据Apache2.0许可证授权的。