Code Monkey home page Code Monkey logo

sam-template-python3.8's Introduction

SAM Template for Python 3.8

This is a template to conveniently get a serverless application model started with Python 3.8. In order to use the template and get started with AWS Lambda functions, you'll need both the AWS and SAM command line interfaces installed.

Once installed, the template can be downloaded from this repository directly into a specified directory on your local machine.

The file structure that will be generated for your SAM-initialized project based on this template is below.

File Structure

.
├── Makefile
├── README.md
├── events
│   └── event.json
├── requirements.txt
├── src
│   └── service
│       ├── __init__.py
│       └── app.py
├── template.yaml
└── tests
    └── unit
        ├── __init__.py
        └── test_handler.py

It's important to understand that the main goal of the template is to make life easier by bypassing some of the nitty-gritty and often tedious steps to create, build, and deploy a successful Lambda application.

Initialize

To that end, the first step is to initialize your project with this command:

sam init -l gh:aridyckovsky/sam-template-python3.8

It will prompt you for a project name, defaulting to "My App", and that name is used to create a project slug, defaulting to "my-app". You should almost never need to specify a project slug, and simply press enter to the suggested default (which is dynamically produced based on your project name choice).

Build

To build your first Lambda function, run

make build

This is a convenient abstraction over a SAM command. If you'd like to see what that command is, open the Makefile in your project directory.

Local Run

To see if the Lambda function works as expected, run

make run

Again, this overlays the more complicated SAM command, and will invoke the lambda_handler function found at ./src/service/app.py locally. When you use this command, you should see the underlying SAM invokation (i.e., sam local invoke ...), and then a console message stating

Invoking service.app.lambda_handler (python3.8)

If the handler runs successfully, you will see a a few more messages, and finally a JSON data payload starting with a status code of 200.

Deployment

To deploy the Lambda function, in this case called "Service", to AWS, simply run

make deploy

It will ask a series of questions, and if your AWS credentials are up to date and configured, the command will lead to a new resource being pushed to S3 named after the project and a respective Lambda function.

sam-template-python3.8's People

Contributors

aridyckovsky 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.