11

I'm trying to invoke a lambda function from my AWS CLI in windows 10. I've done previously a configuration of my client thru AWS configure.

The command used is:

aws lambda invoke \
    --function-name arn:aws:lambda:us-east-1:111111111:function:xxx \
    --invocation-type RequestResponse

but my system is returning an error aws: error: too few arguments, as shown below:

enter image description here

Could you guys guide me to succeed in this execution?

thanks

4 Answers 4

23

It looks like you need to provide an outfile. So re-run it as follows:

aws lambda invoke \
    --function-name arn:aws:lambda:us-east-1:111111111:function:xxx \
    --invocation-type RequestResponse \
    outfile.txt
Sign up to request clarification or add additional context in comments.

3 Comments

where is stocked the file outfile.txt? do you know? thanks
It's written to the current working directory, unless you specify an explicit path such as /tmp/outfile.txt.
You are a lifesaver... I was busting my head trying to find an answer for runtime.ImportModuleError cannot find module 'app' when I tried to test my lambda locally - this is probably due to my old windows 8 and docker toolbox
16

In addition to @jarmod's answer: You can use - if want to send output directly to stdout:

aws lambda invoke --function-name my_function --invocation-type RequestResponse --log-type Tail - | grep "LogResult"| awk -F'"' '{print $4}' | base64 --decode

or if you have jq

aws lambda invoke --function-name my_function --invocation-type RequestResponse --log-type Tail - | jq '.LogResult' -r | base64 --decode

2 Comments

I am using this code on Mac-os, but it creates a file in the current directory. The name is of the file is just a dash -. The content of the file are{}. I have to manually delete it each time I run the macro. Specifically, my line of code is this AWS_PAGER="" aws lambda invoke --function-name paypal_ipn --invocation-type RequestResponse --payload fileb://"$tmp_dir"/invoke-payload.json --log-type Tail - | grep "LogResult"| awk -F'"' '{print $4}' | base64 --decode
Also, I do not seem to be able to set an outputfile.txt (like in @jarmod 's answer), or otherwise print out the output of the function using your code.
0

In case you are integrating with Jenkins(Windows) and dont want to use Lambda plugin. Lambda plugin is somehow not taking credentials I set in jenkins binding.

Prepare payload first. I have taken parameters from user.

@echo off
@echo {> payload.json
@echo  "type": "RequestType",>> payload.json
@echo  "siteCode": "%SiteCode%",>> payload.json
@echo  "siteDesc": "%SiteDesc%",>> payload.json
@echo }>> payload.json

Invoke lambda using aws cli.

aws lambda invoke --function-name "FuntionName" --invocation-type RequestResponse --region us-zone-id --log-type Tail --payload file://payload.json response.json

You can print response using type command.

type response.json

Comments

0

AWS CLI version details

aws-cli/2.1.13 Python/3.7.9 Windows/10 exe/AMD64 prompt/off

Invoke Lambda cmd, Payload needs to be Base64 encoded (https://www.base64decode.org/), you can also install plugin if needed

aws configure // If applicable perform the aws configure
aws lambda invoke --function-name test_details:DEV  --payload #yHw response_test.json

success response

{
    "StatusCode": 200,
    "ExecutedVersion": "18"
}

The response_test.json should be generated under same path. Ref document https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/invoke.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.