Code Monkey home page Code Monkey logo

sammy's Introduction

sammy

Python library for generating AWS SAM (Serverless Application Model) templates with validations.

Features

  • Render templates with YAML or JSON
  • Validations are done with Valley

Documentation

Python Versions Supported

  • Python 3.6+

Quick Start

Install

pip install sammy

Simple Example

from sammy import SAM, Function, API, SimpleTable

f = Function('testpublish',Handler='s3imageresize.handler',
             Runtime='python3.6',
             CodeUri='s3://your-bucket/photoresizer.zip')

ddb = SimpleTable('maintable',PrimaryKey={'Name':'_id','Type':'String'})

s = SAM(render_type='yaml')

s.add_resource(f)
s.add_resource(ddb)

print(s.to_yaml())

SAM

SAM is the class that generates the SAM template.

from sammy import SAM, SimpleTable

s = SAM(resources=[SimpleTable('maintable',PrimaryKey={'Name':'_id','Type':'String'})],
render_type='json')

Keyword Arguments

  • resources - List of resource classes (API, SimpleTable, or Function)
  • render_type - This is a string and there are only two options JSON or YAML.

Methods

add_resource(resource)

Add a resource class to the template

Example
from sammy import Function, SAM

s = SAM(render_type='json')

f = Function('testpublish',Handler='s3imageresize.handler',
             Runtime='python3.6',
             CodeUri='s3://your-bucket/photoresizer.zip')

s.add_resource(f)
add_parameter(parameter)

Add a parameter class to the template

Example
import sammy as sm

s = sm.SAM(render_type='json')

s.add_parameter(sm.Parameter(name='Bucket',Type='String'))
get_template_dict()

Returns Python dict object representation of the template.

to_json()

Returns a JSON representation of the template.

to_yaml()

Returns a YAML representation of the template.

get_template()

Returns a YAML or JSON representation of the template depending on what you set the render_type to on initialization.

publish_template(bucket_name)

Publishes the SAM template to S3

publish(stack_name)

Publishes the SAM template to Cloudformation

Function

This class represents an AWS Lambda function

from sammy import Function

f = Function('testpublish',Handler='s3imageresize.handler',
             Runtime='python3.6',
             CodeUri='s3://your-bucket/photoresizer.zip')

API

This class represents an AWS API Gateway

from sammy import API

a = API(StageName='dev',DefinitionUri='s3://your-bucket/your-swagger.yml',
    CacheClusterEnabled=False,CacheClusterSize=None,Variables={'SOME_VAR':'test'})

SimpleTable

This class represents a simple DynamoDB table

from sammy import SimpleTable

ddb = SimpleTable('maintable',PrimaryKey={'Name':'_id','Type':'String'})

Ref

This class represents a reference

import sammy as sm


sam = sm.SAM(Description='A hello world application.',render_type='yaml')

sam.add_parameter(sm.Parameter(name='Bucket',Type='String'))

sam.add_parameter(sm.Parameter(name='CodeZipKey',Type='String'))

sam.add_resource(
    sm.Function(name='HelloWorldFunction',
        Handler='sample.handler', Runtime='python3.6', CodeUri=sm.S3URI(
            Bucket=sm.Ref(Ref='Bucket'),Key=sm.Ref(Ref='CodeZipKey'))))

sammy's People

Contributors

babyhuey avatar bjinwright avatar brianjinwright avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.