作者:Philipp Gorczak

### 作者邮箱:p.gorczak@gmail.com

### 首页:https://github.com/pgorczak/awslambda

### 文档:None

### 下载链接

awslambda

A tool for deploying Python projects to AWS Lambda.

Getting started

Authentication is left to boto3 so you can set it up just like the regular AWS CLI . You need an S3 bucket for temporary storage. For a quick tutorial on execution roles, see the official docs _ (of course you need one that can execute lambdas).

In a new folder, create mymodule.py.

.. code:: python

def hello(*args):

return "Hello, world!"

Then deploy the function (fill in your execution role resource name from the AWS console).

::

awslambda . mybucket --create hello mymodule.hello arn:aws:iam::xxxxxxxxxxxx:role/myrole

When awslambda is done, you can test your new function in the Lambda management console.

From now on, if you make changes to the function, just run:

::

awslambda . mybucket --update hello

You can use as many options as you like (some shown here with short names).

::

awslambda . mybucket -u hello -u myotherlambda --delete myoldlambda

Or specify your functions in a YAML file (let's call it sync.yaml).

.. code:: yaml

hello:

handler: mymodule.hello

role: arn:aws:iam::xxxxxxxxxxxx:role/myrole

# myotherlambda:

# handler: myothermodule.myotherhandler

# role: arn:aws:iam::xxxxxxxxxxxx:role/myrole

When syncing from a file, awslambda will update existing functions and create the others automatically.

::

awslambda . mybucket --sync sync.yaml

To add dependencies, use your pip requirements file _.

::

awslambda . mybucket -s sync.yaml --requirements requirements.txt

Note that compiled dependencies awslambda downloads on your local machine might not work on the AWS servers. Pure Python libraries should always work. For others, it could be helpful to run awslambda itself in a Lambda function. A process knows as awslambdaception.

A template greeting page ........................

Let's use the features introduced above to create a greeting page. We will use the Jinja2 _ templating engine. Edit mymodule.py,

.. code:: python

from jinja2 import Template

template = Template('''

Hello, {{ parameters.name }}!

{{ parameters.message }}

''')

def hello(event, context):

return {

'statusCode': 200,

'headers': {'Content-Type': 'text/HTML'},

'body': template.render(parameters=event['queryStringParameters'])}

and create a simple requirements.txt.

::

Jinja2

Deploy,

::

awslambda . mybucket -s sync.yaml -r requirements.txt

then open the function in your AWS console. Go to Triggers and add an API Gateway trigger. Set security to Open for now. Open the URL of the created trigger in your browser. You should see "Hello, !". To customize the page append e.g.

::

?name=Commander Shepard&message=You've received a new message at your private terminal.

to the URL and enjoy your serverless, templated webpage!

Usage

::

Usage: awslambda [OPTIONS] SOURCEDIR S3BUCKET

Deploy Python code to AWS lambda.

Zips the contents of the source directory together with optional pip

requirements. The archive is temporarily uploaded to an S3 bucket and used

to create or update lambda functions.

Reference handlers from your source directory like you would in any Python

module-tree (e.g. mymodule.myhandler, mymodule.mysubmodule.myhandler,

etc.).

Roles are ARNs like "arn:aws:iam::xxxxxxxxxxxx:role/myrole"

YAML file entries for the sync option map function names to handlers and

roles:

myLambda:

handler: mymodule.myhandler

role: arn:aws:iam::xxxxxxxxxxxx:role/myrole

Options: -r, --requirements PATH pip compatible requirements file. Will be included in the archive. -c, --create NAME HANDLER ROLE Create a new lambda function. Example: --create myLambda mymodule.myhandler myrole -u, --update NAME Update a lambda function. -d, --delete NAME Delete a lambda function. -s, --sync FILENAME Keep lambdas defined in YAML file in sync with deployed lambdas. --help Show this message and exit.

Copy from pypi.org

aws 部署python lambda_awslambda-为Lambda工具部署Python项目。-Philipp Gorczak Getting started Usage...相关推荐

  1. python处理excel的工具-基于Python的Excel处理工具

    ##1 项目描述## 为了减轻妹子工作中处理Excel的辛苦,用python写了几个处理xlsx的代码,分别完成一些独立的任务,如根据考勤记录判断每天未来.迟到.早退的名单,实现两个复杂xlsx文件的 ...

  2. Qt + Python + OpenCV图标替换工具 之 Python调用dll(三)

    目录 上一篇博文 程序的下载地址以及源码 Python调用dll 上一篇博文 Qt + Python + OpenCV图标替换工具 之 获取颜色及生成图片(二) https://blog.csdn.n ...

  3. python懒人小工具:python打包exe 小工具

    不知道有没有菜鸟和我一样,经常需要把python打包成exe,但是比较懒,虽然命令行很简单,但是不太喜欢用命令行,嘿嘿,就干脆写个小工具专门用来打包exe,方便自己用. 多写代码,就当练习了.成品如下 ...

  4. python 编写实用小工具-使用Python制作一个打字训练小工具

    一.写在前面 说道程序员,你会想到什么呢?有人认为程序员象征着高薪,有人认为程序员都是死肥宅,还有人想到的则是996和 ICU. 别人眼中的程序员:飞快的敲击键盘.酷炫的切换屏幕.各种看不懂的字符代码 ...

  5. python 编写实用小工具-toy: python平时积累的笔记以及编写的小工具

    所有人都告诉你怎么活,只有自己没有搞清楚该如何活.相信自己,我们每个人都是主角?? toy Python ?? 献给我亲爱的女朋友--如 ? 介绍 学习 python.matlab 时积累的笔记以及编 ...

  6. python编写sql注入工具-利用Python实现SQL注入 - Python黑客编程入门系列 - 8

    {getUnitName} {getLessonName} 敬请期待 免费 {getTaskName} 剩余观看时长:{watchLimitRemaining} 回放 {activityStartTi ...

  7. Python小白入门- 101 ( 工具篇) Python完成身份证号码校验的算法

    根据国家标准GB 11643-1999<公民身份证号码>的要求: 身份证号码由18位组成,前17位为数字,最后一位是校验码,可能为数字或字母X.其中,前6位是地区代码,接下来8位是出生日期 ...

  8. python五种可视化工具及六道常见面试题

    2017-12-26  吊炸天的  [Python五种可视化工具] 在 Python 中,将数据可视化有多种选择,正是因为这种多样性,何时选用何种方案才变得极具挑战性.本文包含了一些较为流行的工具以及 ...

  9. Python 匿名函数 lambda - Python零基础入门教程

    目录 一.Python 匿名函数 lambda 语法 二.Python 匿名函数 lambda 调用 1.lambda 匿名函数常规使用 2. lambda 匿名函数使用不定长参数 3. lambda ...

最新文章

  1. bzoj 3120 矩阵优化DP
  2. Java Review - 并发组件ConcurrentHashMap使用时的注意事项及源码分析
  3. VTK:图片之ImageOpenClose3D
  4. Js中清空文件上传字段(input type=file )
  5. 【dfs】病毒(jzoj 1284)
  6. 前端学习(1964)vue之电商管理系统电商系统之渲染分类参数的tab页标签
  7. Android-Activity中的onNewIntent()方法调用简析
  8. 【转】C#获取当前日期时间(转)
  9. java代码执行效率分析
  10. 火山软件开发平台(安卓)实现“腾迅X5浏览器”读取本地资源
  11. attempting to load a 64-bit
  12. 浅谈域名抢注和域名投资
  13. 神经元示踪染料RH 237的功能和研究意义
  14. 刚子扯谈:“爆吧”圣斗士们,你妈没叫你回家吃饭
  15. 2022世界杯期间,独立站卖家如何借势营销?
  16. 关于根轨迹对于控制系统的一点理解
  17. 房天下APP竞品分析
  18. 灵魂的吞噬 评论google图书馆
  19. 安装 synaptic on ubuntu 18
  20. OpenCV作业及近阶段学习总结

热门文章

  1. java线程——详解Callable、Future和FutureTask
  2. 读写锁分离的循环队列
  3. devstack安装openstack
  4. 通过判断流的头 判断文件类型
  5. Node学习记录: 图片爬虫
  6. 《浪潮之巅》读书笔记3
  7. ubuntu mysql lessons
  8. with(nolock)解释
  9. SonicWall 防火墙曝严重漏洞,有些设备仍无补丁
  10. 浅谈RNN、LSTM + Kreas实现及应用