Amazon AWS CLI not allowing valid JSON in payload parameter

后端 未结 2 486
野趣味
野趣味 2021-01-01 09:38

I am getting an error when I try and invoke a lambda function from the AWS CLI. I am using version 2 of the CLI. I understand that I should pass the --payload a

相关标签:
2条回答
  • 2021-01-01 10:17

    As @MCI said, AWS V2 defaults to base 64 input. For your case to work, simply add a --cli-binary-format raw-in-base64-out parameter to your command, so it'd be

    aws lambda invoke --function-name testsms \
        --invocation-type Event \
        --cli-binary-format raw-in-base64-out \
        --payload '{"key": "test"}' response.json
    
    0 讨论(0)
  • 2021-01-01 10:29

    Looks like awscli v2 requires some parameters be base64-encoded.

    By default, the AWS CLI version 2 now passes all binary input and binary output parameters as base64-encoded strings. A parameter that requires binary input has its type specified as blob (binary large object) in the documentation.

    The payload parameter to lamba invoke is one of these blob types that must be base64-encoded.

    --payload (blob) The JSON that you want to provide to your Lambda function as input.

    One solution is to use openssl base64 to encode your payload.

    echo '{"key": "test"}' > clear_payload  
    openssl base64 -out encoded_payload -in clear_payload
    aws lambda invoke --function-name testsms  --invocation-type Event --payload file://~/encoded_paylaod response.json
    
    0 讨论(0)
提交回复
热议问题