Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create an AWS Lambda function using the AWS CLI?

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?

like image 692
sheki Avatar asked Dec 18 '15 19:12

sheki


People also ask

How do you call a lambda function in AWS CLI?

Creating AWS Lambda Function using AWS CLI--function-name − Specify the name of the function you want to invoke. --invocation-type(string) − by default the invokation-type is requestresponse. The values available to be used with invokation-type is RequestResponse, Event and DryRun.

What are the steps used to create a lambda function?

Step 1: Create a Lambda Function Your Lambda function receives event data and returns a greeting message. Ensure that your Lambda function is under the same AWS account and AWS Region as your state machine. Open the Lambda console and choose Create function. On the Create function page, choose Author from scratch.

What AWS command line interface CLI command would you use to share your Lambda based application publicly?

You can use the AWS SAM CLI sam build command with the --use-container to create your deployment package. This option builds a deployment package inside a Docker image that is compatible with the Lambda execution environment. For more information, see sam build in the AWS Serverless Application Model Developer Guide.


2 Answers

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'
like image 170
helloV Avatar answered Oct 03 '22 21:10

helloV


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
like image 33
Soshmo Avatar answered Oct 03 '22 21:10

Soshmo