Last active
April 25, 2019 01:22
-
-
Save rtancman/a7b6ebcc2442146b8857cf97a4d08b51 to your computer and use it in GitHub Desktop.
Python + Lambda - Otimizando o processo com Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM amazonlinux | |
RUN yum update -y | |
RUN yum groupinstall "Development Tools" -y | |
RUN yum install -y \ | |
gcc \ | |
bzip2-devel \ | |
libffi \ | |
openssl-devel \ | |
perl-core \ | |
zlib-devel \ | |
libxml2-devel \ | |
libxslt-devel \ | |
libffi-devel \ | |
libcffi-devel \ | |
wget \ | |
postgresql96-devel \ | |
mysql56-devel \ | |
sqlite | |
RUN curl -O http://download.redis.io/redis-stable.tar.gz && \ | |
tar xvf redis-stable.tar.gz && \ | |
cd redis-stable && \ | |
make && make install && rm -rf redis-stable.tar.gz | |
ENV PYTHON_VERSION 3.7.2 | |
RUN cd /usr/src/ && \ | |
wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz && \ | |
tar xzf Python-$PYTHON_VERSION.tgz && \ | |
cd Python-$PYTHON_VERSION && \ | |
./configure --enable-optimizations && \ | |
make altinstall && \ | |
cd / && rm -rf /usr/src/Python-$PYTHON_VERSION.tgz && python3.7 -V | |
RUN pip3.7 install --upgrade pip && pip3.7 install awscli setuptools wheel | |
RUN mkdir /app | |
WORKDIR /app | |
CMD /bin/bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FUNCTION_NAME ?= lambdamake | |
FUNCTION_ROLE ?= XXXXXXXXXXX | |
docker.build: | |
@echo "---- Create amazon linux image base ----" | |
docker build -t amazon-linux-python37 . | |
lambda.build: docker.build lambda.clear | |
@echo "---- Create Lambda Package using amazon linux image base ----" | |
docker run --rm -u `id -u` \ | |
-v ~/.aws/:/home/lambda/.aws/ \ | |
-v `pwd`:/app \ | |
-e "HOME=/home/lambda" \ | |
amazon-linux-python37 pip3.7 install -r requirements.txt -t . | |
lambda.clear: | |
rm -rf $(FUNCTION_NAME).zip | |
lambda.zip: lambda.build | |
zip -qr $(FUNCTION_NAME).zip . | |
lambda.create: lambda.zip | |
aws lambda create-function \ | |
--region us-east-1 \ | |
--handler main.handle \ | |
--runtime python3.7 \ | |
--function-name '$(FUNCTION_NAME)' \ | |
--zip-file fileb://./$(FUNCTION_NAME).zip \ | |
--role '$(FUNCTION_ROLE)' | |
lambda.update: lambda.zip | |
aws lambda update-function-code \ | |
--region us-east-1 \ | |
--function-name '$(FUNCTION_NAME)' \ | |
--zip-file fileb://./$(FUNCTION_NAME).zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment