Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 09c8b69

Browse files
committed
[Start] Initial Commit
Additions, changes/fixes and removals Additions: - Added Dockerfile - Added entrypoint.sh - Added action.yml Fixes: - N\A Changes: - N\A Removed: - N\A Integrations: N\A
1 parent 825872c commit 09c8b69

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python:3.8
2+
3+
RUN apt-get update
4+
RUN apt-get install -y jq zip
5+
RUN pip install awscli
6+
7+
ADD entrypoint.sh /entrypoint.sh
8+
RUN chmod +x /entrypoint.sh
9+
ENTRYPOINT ["/entrypoint.sh"]

action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: AWS Lambda Zip Deploy - Python
2+
author: Qubitro
3+
description: Zip deploy to AWS Lambda with requirements in a separate layer.
4+
inputs:
5+
requirements_txt:
6+
description: the name/path to the requirements.txt file
7+
required: true
8+
default: 'requirements.txt'
9+
lambda_layer_arn:
10+
description: The ARN for the Lambda layer the dependencies should be pushed to without the version (every push is a new version).
11+
required: true
12+
lambda_function_name:
13+
description: The Lambda function name. Check the AWS docs/readme for examples.
14+
required: true
15+
runs:
16+
using: 'docker'
17+
image: 'Dockerfile'
18+
args:
19+
- ${{ inputs.requirements_txt }}
20+
- ${{ inputs.lambda_layer_arn }}
21+
- ${{ inputs.lambda_function_name }}
22+
- ${{ inputs.lambda_region }}
23+
branding:
24+
icon: 'cloud-lightning'
25+
color: 'white'

entrypoint.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
configure_aws_credentials(){
4+
aws configure set aws_access_key_id "${INPUT_AWS_ACCESS_KEY_ID}"
5+
aws configure set aws_secret_access_key "${INPUT_AWS_SECRET_ACCESS_KEY}"
6+
aws configure set default.region "${INPUT_LAMBDA_REGION}"
7+
}
8+
9+
install_zip_dependencies(){
10+
echo "Installing and zipping dependencies..."
11+
mkdir python
12+
pip install --target=python -r "${INPUT_REQUIREMENTS_TXT}"
13+
zip -r dependencies.zip ./python
14+
}
15+
16+
publish_dependencies_as_layer(){
17+
echo "Publishing dependencies as a layer..."
18+
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip)
19+
LAYER_VERSION=$(jq '.Version' <<< "$result")
20+
rm -rf python
21+
rm dependencies.zip
22+
}
23+
24+
publish_function_code(){
25+
echo "Deploying the code itself..."
26+
zip -r code.zip . -x \*.git\*
27+
aws lambda update-function-code --function-name "${INPUT_LAMBDA_FUNCTION_NAME}" --zip-file fileb://code.zip
28+
}
29+
30+
update_function_layers(){
31+
echo "Using the layer in the function..."
32+
aws lambda update-function-configuration --function-name "${INPUT_LAMBDA_FUNCTION_NAME}" --layers "${INPUT_LAMBDA_LAYER_ARN}:${LAYER_VERSION}"
33+
}
34+
35+
deploy_lambda_function(){
36+
configure_aws_credentials
37+
install_zip_dependencies
38+
publish_dependencies_as_layer
39+
publish_function_code
40+
update_function_layers
41+
}
42+
43+
deploy_lambda_function
44+
echo "Each step completed, check the logs if any error occured."

0 commit comments

Comments
 (0)