sunmingtao / sample-code

3 stars 4 forks source link

Fail to invoke Lambda function, uninstall aws-cli version 1, Invoke Lambda function asynchronously. #137

Closed sunmingtao closed 4 years ago

sunmingtao commented 4 years ago

Run aws lambda list-functions --region ap-southeast-2

Display

{
    "Functions": [
        {
            "FunctionName": "smt-lambda-function",
            "FunctionArn": "arn:aws:lambda:ap-southeast-2:527875336349:function:smt-lambda-function",
            "Runtime": "python3.7",
            "Role": "arn:aws:iam::527875336349:role/service-role/smt-lambda-function-role-la5wymst",
            "Handler": "lambda_function.lambda_handler",
            "CodeSize": 343,
            "Description": "A starter AWS Lambda function.",
            "Timeout": 3,
            "MemorySize": 128,
            "LastModified": "2020-05-24T05:48:40.945+0000",
            "CodeSha256": "qk5aJjSVYCuOgCpy79x2Gbf5N/+CRhnlg1Ho5+iVFDI=",
            "Version": "$LATEST",
            "TracingConfig": {
                "Mode": "PassThrough"
            },
            "RevisionId": "d6067a62-97b9-48f5-8cc0-c59c6efbdcef"
        }
    ]
}

Run aws lambda invoke --function-name smt-lambda-function --cli-binary-format raw-in-base64-out --payload '{"key1": "value1", "key2": "value2", "key3": "value3" }' --region ap-southeast-2 response.json

Get error

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help

Unknown options: --cli-binary-format, response.json
sunmingtao commented 4 years ago

Getting rid of --cli-binary-format raw-in-base64-out works

aws lambda invoke --function-name smt-lambda-function --payload '{"key1": "value1", "key2": "value2", "key3": "value3" }' --region ap-southeast-2 response.json

Turns out --cli-binary-format is only supported in CLI version 2

sunmingtao commented 4 years ago

To uninstall AWS-CLI version 1:

pip3 uninstall awscli -y

Then install aws-cli version 2 Download from https://awscli.amazonaws.com/AWSCLIV2.pkg and double click to install Open a new terminal window aws --version

sunmingtao commented 4 years ago

To invoke the lambda function asynchronously , aws lambda invoke --function-name smt-lambda-function --cli-binary-format raw-in-base64-out --payload '{"key1": "value1", "key2": "value2", "key3": "value3" }' --invocation-type Event --region ap-southeast-2 response.json