Is it possible to update Lambda function with .jar uploaded to S3? - amazon-web-services

I'm trying to update Lambda code with .jar file uploaded to S3.
Direct zip file upload works fine
aws lambda update-function-code --function-name function
--zip-file fileb://function.zip
Direct jar file upload works fine
aws lambda update-function-code --function-name function
--zip-file fileb://function.jar
Update with zip file from S3 works fine
aws lambda update-function-code --function-name function --s3-bucket bucket
--s3-key function.zip
Problem appears only when updating function with jar from S3
aws lambda update-function-code --function-name function --s3-bucket bucket
--s3-key function.jar
Apparently AWS Lambda tries to unpack the jar:
An error occurred (InvalidParameterValueException) when calling the UpdateFunctionCode operation: Unzipped size must be smaller than 262144000 bytes
I couldn't find any clue in update-function-code reference https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-code.html
Is it possible to update Lambda function with jar file from S3?
If no, is there any reference saying so?

You've hit the 250MB upload limit, that's all I can say from the error message.
Solution: Work on your application, or ask support to raise the limit.
Lambda size can be 250 MB (unzipped, including layers) for s3 uploads.
Direct uploads is 50MB (compressed), but this goes little higher to ~70MB & it uses based64 encoding.
You don't see errors on directly uploading for compressed (zip/jar) file <70MB.
If you don't want jar files to be extracted, you must zip it. Zip will be extracted!
Could probably tell more if you update with size of zip, jar, dependencies and presence of layers.

Related

Delete old versions of lambda functions uploaded through CloudFormation package command

I am using aws cloudformation package to automatically package and upload Lambda function code to an S3 bucket.
When I upload a new version of the Lambda function, previous objects remain in the S3 bucket. Is there any way to automatically remove "old" versions when uploading a new one?
Sadly there is no such way with just aws cloudformation package command. You would have to chain with other command to delete (aws s3api delete-object) the previous version yourself.

Why sam package publishes the artifacts to bucket?

As part of packaging the SAM application, the application published to s3 bucket as shown below:
sam package --template-file sam.yaml --s3-bucket mybucket --output-template-file output.yaml
Why sam package provides --s3-bucket option? Is this mandatory option?
What is the purpose of publishing artifacts to s3 bucket?
--s3-bucket option in sam package command is mandatory. What the command does is that it takes your local code, uploads it to S3 and returns transformed template where source location of your local code has been replaced with the S3 bucket URI (URI of object - zipped code - in the S3 bucket).
Main advantage of uploading artifact to S3 is that it is faster to deploy code that already sits within AWS network than send it through the Internet during deployment.
Another thing is that plain CloudFormation let's you inline lambda function code without pushing it to S3 but there are limitations to this approach. If your lambda function needs to use external libraries that are not part of AWS provided lambda environment for a particular runtime or your function's size is big then you still need to zip your function's code together with its dependencies and upload it to S3 before continuing. SAM just makes this easier for you so that you don't have to do this step manually.

AWS- AWS command to view lambda function in Command Line

My Lambda function code can't be viewed in the AWS Console due to an error with the file being too large. Is there an AWS command to pull the Lambda function code and view it in the command line?
Or, can I push my lambda code onto an S3 bucket, then download it from there to view it? Is there a command for that?
Download the Lambda function code from the AWS console, or use the AWSCLI as follows:
aws lambda get-function --function-name xyz --region <region>
This will return a presigned URL link to the .zip file containing your Lambda function.

AWS lambda update-function-code with jar package via AWS CLI

I'm trying to update my lambda function code with jar from my local machine via AWS CLI.
The aws lambda has commands to update function code for zip file but not for jar.
I can upload by using s3 bucket, but I need to update from local itself.
I know following are the way to update from S3 bucket and for zip:
aws lambda update-function-code --function-name
--s3-bucket --s3-key
aws lambda update-function-code --function-name
--zip-file "fileb://"
I want to ask is there similar command exist for uploading jar as well?
You're probably missing the "fileb://" part for the jar.
aws lambda update-function-code --function-name my-lambda-name --zip-file fileb://./target/my-lambda-jar.1.0-SNAPSHOT.jar
run this command:
aws lambda update-function-code --function-name my-lambda-name --zip-file fileb://./target/my-lambda-jar.1.0-SNAPSHOT.jar

AWS lambda function with python "errorMessage": "Unable to import module 'index'"

i am trying to make a post call from lambda function but not able to run the code on aws console but it it working properly on my system.
You need to install the dependencies in the folder where you have index.py then you need to zip the contents of the folder and upload the zip file to AWS Lambda.
Please note that you need to zip the contents of the folder, do not zip the folder itself.
On windows, you can install the packages in the folder using below command:
pip install package-name -t "/path/to/project-dir"
I had this error today, and this is the first result on Google, so I'll add my answer. In short, I had specified the handler incorrectly on the command line when I uploaded the function.
aws lambda create-function --function-name python-test-lambda --runtime python3.7 --role arn:aws:iam::123123123123:role/service-role/rolearn --handler lambda_function.lambda_handler --zip-file fileb://lambda_function.zip
ie this part was incorrect
--handler