I am deploying aws handler scripts as zip files in S3 bucket. Now, I want to use this deployed zipped file in lambda function. I am doing all of this via gitlab CI.
I have the following CI:
image: ubuntu:18.04
variables:
GIT_SUBMODULE_STRATEGY: recursive
AWS_DEFAULT_REGION: eu-central-1
S3_BUCKET: $BUCKET_TRIAL
stages:
- deploy
.before_script_template: &before_script_definition
stage: deploy
before_script:
- apt-get -y update
- apt-get -y install python3-pip python3.7 zip
- python3.7 -m pip install --upgrade pip
- python3.7 -V
- pip3.7 install virtualenv
.after_script_template: &after_script_definition
after_script:
# Upload package to S3
# Install AWS CLI
- pip install awscli --upgrade # --user
- export PATH=$PATH:~/.local/bin # Add to PATH
# Configure AWS connection
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
- aws configure set default.region $AWS_DEFAULT_REGION
- aws sts get-caller-identity --output text --query 'Account'
- aws s3 cp ~/forlambda/archive.zip $BUCKET_TRIAL/${LAMBDA_NAME}-deployment.zip
- aws lambda create-function --function-name "${LAMBDA_NAME}-2" --runtime python3.7 --role arn:aws:iam::xxxxxxxxxxxx:role/abc_scripts --handler ${HANDLER_SCRIPT_NAME}.${HANDLER_FUNCTION} --memory-size 1024 --zip-file "fileb://$BUCKET_TRIAL/${LAMBDA_NAME}-deployment.zip"
my_job:
variables:
LAMBDA_NAME: my_lambda
HANDLER_SCRIPT_NAME: my_aws_handler
HANDLER_FUNCTION: my_handler_function
<<: *before_script_definition
script:
# - move scripts around and install requirements and zip the file for lambda deployment
<<: *after_script_definition
For the CI, I have added Environment variables $BUCKET_TRIAL and is of the form s3://my-folder
When the CI file is run, it throws the following error in the end:
Error parsing parameter '--zip-file': Unable to load paramfile fileb://s3://my-folder/my_lambda-deployment.zip: [Errno 2] No such file or directory: 's3://my-folder/my_lambda-deployment.zip'
I also tried changing the --zip-file in the last line of the after_script as:
- aws lambda create-function --function-name "${LAMBDA_NAME}-2" --runtime python3.7 --role arn:aws:iam::xxxxxxxxxxxx:role/abc_scripts --handler ${HANDLER_SCRIPT_NAME}.${HANDLER_FUNCTION} --memory-size 1024 --zip-file "fileb:///my-folder/${LAMBDA_NAME}-deployment.zip"
But it still throws the same error.
Am I missing something here?
Based on the discussion in chat.
The solution was to use
--zip-file fileb:///root/forlambda/archive.zip
instead of
--zip-file "fileb://$BUCKET_TRIAL/${LAMBDA_NAME}-deployment.zip"
The reason is that --zip-file requires a local path to a zip deployment package, rather than a remote location in s3.
From docs:
--zip-file (blob): The path to the zip file of the code you are uploading. Example: fileb://code.zip
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With