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
Related
I want to create a lamba deployment package in python (with dependencies) using the Amazon tutorial.
When I push the .zip package with
aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip
I get the following error
An error occurred (AccessDeniedException) when calling the UpdateFunctionCode operation:
User: arn:aws:iam::<ACCOUNT-ID>:user/jeanclaude is not authorized to perform: lambda:UpdateFunctionCode
on resource: arn:aws:lambda:eu-west-3:<ACCOUNT-ID>:function:my-function
Which policy should I grant to jeanclaude to give him the correct access?
The User created in AWS IAM which is configured with your AWS CLI using access_key and secret_key should have enough privileges to interact with AWS Lambda.
I would prefer AWSLambdaFullAccess policy attached to your User/Role. This is just for testing purpose and later you can reduce the privileges if you want.
Once you have done the above then if you run the command
aws lambda update-function-code --function-name "helloworld" --zip-file "fileb://./helloworld.zip" --region "eu-west-2"
it should work, note that for update-function-code mandatory field is just the --function-name other fields are optional.aws cli update-fuction-code
Also please take a note of the create-function command it has just the following fields as mandatory and all other are optional aws cli docs
create-function
--function-name <value>
--runtime <value>
--role <value>
--handler <value>
and the --role here is the role required by the lambda while executing to interact with other services (not to be confused by the user above)
The user needs permission to UpdateFunctionCode for that ARN. More specific information is here.
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.
Basically, I want to know if I can configure everything you see in this image from the AWS CLI. It seems like I can't.
Can I modify this Lambda config to provide an S3 link and function handler all from the CLI?
Yes, using the create-function call.
aws lambda create-function \
--runtime python3.6 \
--handler file_name.lambda_handler \
--code S3Bucket=mybucket,S3Key=path/to/object.zip
Am i missing something ? it seems that you can use --profile with almost any other aws cli functionality.
is there any other way around this then by manually running aws configure ?
update Lambda environment variables from JSON file
aws lambda update-function-configuration --profile mfa --function-name test-api --cli-input-json file://dev.json
I am trying to create an AWS Lambda function using the command
aws lambda create-function \
--function-name foo\
--runtime nodejs\
--role lambda_basic_execution \
--handler asdf --zip-file "fileb:://boom.zip"
I have a file called boom.zip available in the directory. But I cannot deploy using the above command.
The failure message I get is
--zip-file must be a file with the fileb:// prefix.
Does anyone have a working example to create a lambda function using the AWS CLI?
You have an extra colon ':' in the file spec.
$ aws lambda create-function --function-name foo --runtime nodejs --role lambda_basic_execution --handler asdf --zip-file "fileb:://boom.zip"
--zip-file must be a file with the fileb:// prefix.
Example usage: --zip-file fileb://path/to/file.zip
$ aws lambda create-function --function-name foo --runtime nodejs --role lambda_basic_execution --handler asdf --zip-file "fileb://boom.zip"
Error parsing parameter '--zip-file': Unable to load paramfile fileb://boom.zip: [Errno 2] No such file or directory: 'boom.zip'
On mac I had to use absolute path, but added to the prefix there are actually 3 slashes.
Prefix:
fileb://
Path
/Users/myuser/Apps/folder/zips/file.zip
Complete
fileb:///Users/myuser/Apps/folder/zips/file.zip
I've had the same issue on Ubuntu 18.04 and what did the trick was enclosing both the name of the function and the fileb:/// with double " quotes.
aws lambda update-function-code --function-name "FUNCTION" --zip-file "fileb:///an/absolute/path/to/your/lambda/FUNCTION.zip"
For me, the issue occurred (in windows) because I didn't create the zip file correctly. I used the winrar tool to create the .rar file, changed the extension to .zip, and tried to upload the zip in the same way #helloV said (without double ::), but I got the same error message. If you are in windows make sure to follow this guide (for golang), or use any other suitable tool to create a correct zip file and try the command out again.