9
votes

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

4 Answers

20
votes

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
13
votes

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

0
votes

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
0
votes

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