Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PROJECT = myProject
- FUNCTION = $(PROJECT)
- REGION = ap-southeast-1
- ROLE = arn:aws:iam::123456789012:role/service-role/myLambdaRole
- createFunction:
- aws lambda create-function \
- --region $(REGION) \
- --function-name $(PROJECT) \
- --zip-file fileb://$(FUNCTION).zip \
- --role $(ROLE) \
- --environment Variables="{HOST='0.0.0.0',PORT=22,USERNAME='user',PASSWORD='password',REMOTEFILE='to/remote/file'}" \
- --handler $(PROJECT).handler \
- --runtime python2.7 \
- --profile <adminuser> \
- --timeout 10 \
- --memory-size 1024
- packageDependencies:
- zip -r9 $(FUNCTION).zip $(PROJECT).py
- mkdir -p site-packages
- virtualenv $(FUNCTION)
- . $(FUNCTION)/bin/activate; pip install -r requirements.txt;\
- cd site-packages; cp -r $$VIRTUAL_ENV/lib/python2.7/site-packages/ ./;\
- cp -r $$VIRTUAL_ENV/lib64/python2.7/site-packages/ ./;\
- cd site-packages; zip -r9 ../../$(FUNCTION).zip .
- updateFunction:
- aws lambda update-function-code \
- --region $(REGION) \
- --function-name $(PROJECT) \
- --zip-file fileb://$(FUNCTION).zip \
- --publish\
- --profile <adminuser>
- manualInvoke:
- aws lambda invoke \
- --invocation-type RequestResponse \
- --function-name $(FUNCTION) \
- --region $(REGION) \
- --profile <adminuser> \
- outputfile.txt
- deleteFunction:
- aws lambda delete-function \
- --function-name $(FUNCTION) \
- --region $(REGION) \
- --profile <adminuser>
- # Schedule the Lambda Function
- # Step 1:
- createRule:
- aws events put-rule \
- --region $(REGION) \
- --name $(FUNCTION)-rule \
- --schedule-expression 'cron(0/5 8-17 ? * MON-FRI *)' \
- --profile <adminuser>
- # $(ARNRULE) is taken from the put-rule target output and parsed in
- # ARNRULE=arn:aws:events:.....
- # Step 2:
- addPermission:
- aws lambda add-permission \
- --region $(REGION) \
- --function-name $(FUNCTION) \
- --statement-id $(FUNCTION)-event \
- --action 'lambda:InvokeFunction' \
- --principal events.amazonaws.com \
- --source-arn $(ARNRULE) \
- --profile <adminuser>
- putTargets:
- aws events put-targets \
- --region $(REGION) \
- --rule $(FUNCTION)-rule \
- --targets file://targets.json \
- --profile <adminuser>
- clean:
- rm -r $(FUNCTION)
- rm -r $(FUNCTION).zip
- rm -r site-packages
- rm -r outputfile.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement