繁体   English   中英

将python函数上传到aws lambda

[英]Uploading python functions to aws lambda

我开发了两个AWS lambda python函数。 因为我们都需要源代码控制,所以我将我的项目保存在git中。 问题是使用git更新AWS lambda的最佳方法是什么。 AFAIK目前唯一的方法是使用带有update-function-code的aws cli。 我编写了以下bash来手动更新代码:

#!/bin/bash
command -v aws >/dev/null 2>&1 || { echo >&2 "This command requires aws but it's not installed or not in the path.  Aborting."; exit 1; }
bold=$(tput bold)
normal=$(tput sgr0)

if [ "$#" -ne 2 -a "$#" -ne 1 ]; then
    echo "usage: $0 <code file path> [lambda function name if not same]"
    exit 1
fi

if ! [ -e $1 ]; then
    echo "File $1 does not exist"
    exit 1
fi

ZIPFILE="lamzip.zip"
LAMBDA_FUNC="lambda_function.py"

if [ "$#" -ne 2 ]; then
    AWS_LAMBDA_NAME=$(basename $1)
    AWS_LAMBDA_NAME="${AWS_LAMBDA_NAME%.*}"
else
    AWS_LAMBDA_NAME=$2
fi

echo "Will upload your code file to aws lamda ${bold}$AWS_LAMBDA_NAME${normal}"

cp -f $1 /tmp/$LAMBDA_FUNC
rm -f /tmp/$ZIPFILE
zip -j /tmp/$ZIPFILE  /tmp/$LAMBDA_FUNC

CMD="aws lambda update-function-code --function-name $AWS_LAMBDA_NAME --zip-file fileb:///tmp/$ZIPFILE --publish"
echo executing: $CMD
$CMD

exit 0

我是否有jenkins或类似的我可以自动化这个脚本。

但是有更好的方法吗?

编辑 28/1/16更新到我现在使用的脚本它假定脚本名称是aws中的方法名称,除非提供另一个参数

使用构建服务器是部署AWS lambda函数的常用方法,它实际上就像您一样简单。 我们一直在使用非常类似的方法,并且进展顺利。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM