A Python library with convenience helpers for working with the AWS Serverless Application Repository.
Project description
AWS Serverless Application Repository - Python
A Python library with convenience helpers for working with the AWS Serverless Application Repository.
Installation
Simply use pip to install the library:
pip install serverlessrepo
Basic Usage
The serverlessrepo module provides a simple interface for publishing applications and managing application permissions. To get started, import the serverlessrepo module:
import serverlessrepo
Publish Applications
publish_application(template, sar_client=None)
Given an AWS Serverless Application Model (SAM) template, it publishes a new application using the specified metadata in AWS Serverless Application Repository. If the application already exists, it updates metadata of the application and publishes a new version if specified in the template.
For example:
import boto3
from serverlessrepo import publish_application
sar_client = boto3.client('serverlessrepo', region_name='us-east-1')
with open('template.yaml', 'r') as f:
template = f.read()
# if sar_client is not provided, we will initiate the client using region inferred from aws configurations
output = publish_application(template, sar_client)
print (output)
The output of publish_application
has the following structure:
{
'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'}
}
}
There are three possible values for the actions
field:
['CREATE_APPLICATION']
- Created a new application.['UPDATE_APPLICATION']
- Updated metadata of an existing application.['UPDATE_APPLICATION', 'CREATE_APPLICATION_VERSION']
- Updated metadata of an existing application and created a new version, only applicable if a new SemanticVersion is provided in the input template.
details
has different meaning based on the actions
taken:
- If a new application is created, it shows metadata values used to create the application.
- If application is updated, it shows updated metadata values.
- If application is updated and new version is created, it shows updated metadata values as well as the new version number.
update_application_metadata(template, application_id, sar_client=None)
Parses the application metadata from the SAM template and only updates the metadata.
For example:
import boto3
from serverlessrepo import update_application_metadata
sar_client = boto3.client('serverlessrepo', region_name='us-east-1')
with open('template.yaml', 'r') as f:
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 configurations
update_application_metadata(template, application_id, sar_client)
Manage Application Permissions
make_application_public(application_id, sar_client=None)
Makes an application public so that it's visible to everyone.
make_application_private(application_id, sar_client=None)
Makes an application private so that it's only visible to the owner.
share_application_with_accounts(application_id, account_ids, sar_client=None)
Shares the application with specified AWS accounts.
Examples
import boto3
from serverlessrepo import (
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 publicly
make_application_public(application_id, sar_client)
# Make an application private
make_application_private(application_id, sar_client)
# Share an application with other AWS accounts
share_application_with_accounts(application_id, ['123456789013', '123456789014'], sar_client)
Development
- Fork the repository, then clone to your local:
git clone https://github.com/<username>/aws-serverlessrepo-python.git
- Set up the environment:
make init
- Install new packages:
pipenv install [package names]
- Pipenv will automatically update Pipfile and Pipfile.lock for you.
- Add new dependencies to setup.py install_requires if they are needed for consumers of this library.
- Verify that everything works:
make build
- You can run
make tests
separately to verify that tests pass. - Check code style with
make flake
andmake lint
.
- You can run
- Make code changes, run all verifications again before sending a Pull Request:
make pr
License
This library is licensed under the Apache 2.0 License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file serverlessrepo-0.1.3.tar.gz
.
File metadata
- Download URL: serverlessrepo-0.1.3.tar.gz
- Upload date:
- Size: 28.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e10c2d636c47d6aadc101a9d420ba6ca0b4e4f4a2daff02b7c9f7b927e71977 |
|
MD5 | f9f47910fce4097c3882398f6d13ad12 |
|
BLAKE2b-256 | a41d276ed24d24f70466c3a56e0ea39d3a10f98c580c54a99a46208f3fcf0af7 |
File details
Details for the file serverlessrepo-0.1.3-py2.py3-none-any.whl
.
File metadata
- Download URL: serverlessrepo-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f855f6f770ad67acadea7b66a8ef0015cc6b7ae1776bdee8b66435495c1f513 |
|
MD5 | c1adc7564ac04afb74783e30dd1f2d19 |
|
BLAKE2b-256 | fc33a72c09e52ee6ced7ad22e81b2988588a4e5a390a15d3686fbdb85da807b4 |