-
Notifications
You must be signed in to change notification settings - Fork 59
add option to upload dependency layer to S3 first #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rosenbergj
wants to merge
10
commits into
mariamrf:master
Choose a base branch
from
rosenbergj:s3-option
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
964a58e
poll function state before updating layer config
emm218 ccba71d
hopefully fixed problem?
emm218 0c3c424
fixed it for real this time
emm218 07aa199
so many errors aaaaa
emm218 47ffca4
limited what files to deploy, and hopefully fixed polling?
emm218 dbace78
ugh
emm218 ed99978
add option to upload dependency layer to S3 first
e4aadf0
a little more compact
0617bdb
update to python 3.9
rosenbergj e194450
Update to python 3.13
rosenbergj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| FROM python:3.6 | ||
| FROM python:3.13 | ||
|
|
||
| RUN apt-get update | ||
| RUN apt-get install -y jq zip | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,20 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| poll_command="aws lambda get-function --function-name ${INPUT_LAMBDA_FUNCTION_NAME} --query Configuration.[State,LastUpdateStatus]" | ||
|
|
||
| wait_state(){ | ||
| echo "Waiting on function state update..." | ||
| until ${poll_command} | grep "Active" | ||
| do | ||
| sleep 1 | ||
| done | ||
| until ${poll_command} | grep "Successful" | ||
| do | ||
| sleep 1 | ||
| done | ||
| } | ||
|
|
||
| install_zip_dependencies(){ | ||
| echo "Installing and zipping dependencies..." | ||
| mkdir python | ||
|
|
@@ -9,16 +23,24 @@ install_zip_dependencies(){ | |
| } | ||
|
|
||
| publish_dependencies_as_layer(){ | ||
| echo "Publishing dependencies as a layer..." | ||
| local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip) | ||
| if [ "$INPUT_USE_S3" = true ] | ||
| then | ||
| echo "Uploading dependencies to S3..." | ||
| aws s3 cp dependencies.zip s3://"${INPUT_S3_BUCKET_NAME}"/dependencies.zip | ||
| echo "Publishing dependencies from S3 as a layer..." | ||
| local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content S3Bucket="${INPUT_S3_BUCKET_NAME}",S3Key=dependencies.zip) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the file key on S3 should be either configurable or derived from the lambda layer ARN; if the user has more than one lambda layer they would have to have different buckets for it which is not something we should force imo |
||
| else | ||
| echo "Publishing dependencies as a layer..." | ||
| local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip) | ||
| fi | ||
| LAYER_VERSION=$(jq '.Version' <<< "$result") | ||
| rm -rf python | ||
| rm dependencies.zip | ||
| } | ||
|
|
||
| publish_function_code(){ | ||
| echo "Deploying the code itself..." | ||
| zip -r code.zip . -x \*.git\* | ||
| zip -r code.zip *.py -x \*.git\* | ||
| aws lambda update-function-code --function-name "${INPUT_LAMBDA_FUNCTION_NAME}" --zip-file fileb://code.zip | ||
| } | ||
|
|
||
|
|
@@ -31,6 +53,7 @@ deploy_lambda_function(){ | |
| install_zip_dependencies | ||
| publish_dependencies_as_layer | ||
| publish_function_code | ||
| wait_state | ||
| update_function_layers | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s3_bucket_nameis then conditionally required, right? Ifuse_s3is trues3_bucket_namemust be set. If the user does not set it, it will try to upload tono-bucket-name-here. I don't think this should be supported; the error messages might not make sense to the user, and there is a chance, however tiny, that someone owns this bucket.Possible solutions:
use_s3and only keeps3_bucket_namewhich would not have a default and if set, we upload to S3s3_bucket_nameis not explicitly setEither way I don't think we should have a default value for this. What do you think?