AWS EMR: Error parsing parameter: Expected: '=', received: 'EOF' for input: - amazon-web-services

I'm trying to create a cluster from inside one of my EC2 instances. Typing the following command to start my cluster-
aws emr create-cluster --release-label emr-5.20.0 --instance-groups instance-groups.json --auto-terminate and so on...
I receive the following error-
Error parsing parameter '--instance-groups': Expected: '=', received: 'EOF' for input:
instance-groups.json
^
I already tried --instance-groups=instance-groups.json, but I get the same error message.
What's wrong here?

The reason this was failing was because AWS has strict rules when it comes to providing the path for reading files within your EC2 instance.
So, if you want to read the file instance-groups.json (assuming it is in the same directory from where you're running the aws emr CLI command), you must provide file://instance-groups.json as the filename, instead of the straightforward instance-groups.json.

Got this same error message for importing a JSON file in AWS DynamoDB, I was trying to import it from an S3 bucket.
Error parsing parameter '--instance-groups': Expected: '=', received:
'EOF' for input: instance-groups.json
The issues got fixed when I moved file locally and executed the command with file://
So thanks

You have to provide like:-
--key Name=123456789

Had similar error as "Expected: ',', received: 'EOF' for input:". I noticed there was a string with space in one of my arguments. Fixed the space issue and it was resolved.

--lifecycle-configuration file://C:/Users/MyUser/Desktop/AMZ/lifecycle.json
This way works too.

Related

Invoking AWS Lambda via CLI returns ERROR: Could not parse payload into json: Unexpected character ((CTRL-CHAR, code 145)):

I am trying to follow along the AWS Getting Started with Lambda Tutorial, but I am having Issues actually invoking my Function using the CLI.
I came across THIS step and got two errors:
An error occurred (InvalidRequestContentException) when calling the
Invoke operation: Could not parse request body into json: Could not
parse payload into json: Unexpected character ((CTRL-CHAR, code 145)):
expected a valid value (JSON String, Number, Array, Object or token
'null', 'true' or 'false') at [Source: (byte[])"��j[�"; line: 1,
column: 2]
and
An error occurred (ResourceNotFoundException) when calling the
GetLogEvents operation: The specified log group does not exist.
I assume the first error is caused by the first command :
aws lambda invoke --function-name my-function --payload '{"key": "value"}' out.json
and the second error accordingly by:
aws logs get-log-events --log-group-name /aws/lambda/my-function --log-stream-name $(cat out) --limit 5
I am more concerned about the first error.
I tried to solve this, by looking at the documentation for invoking a lambda function using the CLI. The most basic example was:
aws lambda invoke --function-name my-function --payload '{ "key":
"value" }' response.json
Using this, I get the same Error code
Could not
parse payload into json: Unexpected character ((CTRL-CHAR, code 145)):
I have asked about this in the AWS Dev Forums, but have not gotten any answer.
There where a few topics about similar errors on Stackoverflow, however they mentioned a specific character that was missing in the payload to be valid JSON.
According to google "CTRL-CHAR" sometimes points out a line break in your JSON, but there are none in this example. As far, as I can tell, the payload is valid JSON.
According to the CLI Documentation, you can also use other data types as payload. So I tried just passing a list:
aws lambda invoke --function-name my-func2 --payload '[2, 3, 4, 5]' out.json
I got the error:
Could not parse request body into json: Could not parse payload into
json: Unrecognized token 'Û': was expecting (JSON String, Number,
Array, Object or token 'null', 'true' or 'false')
Just in case anyone ever gets stuck at the same point while doing the official Lambda Tutorial:
I had the issue solved by adding:
--cli-binary-format raw-in-base64-out
as a parameter.
According to : CLI 2 AWS DOCS
This has something to do with encoding changes from CLI 1 to CLI 2.
It can also be added to to the aws config file, so you dont have to add it manually every time.
However, I am not sure why the Lambda Tutorial would not mention this, since the tutorial assumes you use CLI 2 and also guides you through the steps of the installation...
For me this way it worked in windows:
aws lambda invoke --function-name Func2 --payload {\"key1\":\"val1\"} --cli-binary-format raw-in-base64-out out.json
As suggested by MrTony, I added "--cli-binary-format raw-in-base64-out" args

aws ses automation script : Error parsing parameter '--destination': Expected: '=', received: '#' for input:

I've been a reader for a while. Usually deal with stuff on my own but today I need a hint.
So I've been tasked to run an email campaign at my new job (100k audience) with minimal budget spent and very short notice (tomorrow). I leaned toward AWS (Amazon Web Services) because Amazon SES (Simple Email Service) is very cheap and you only pay what you use.
tried to use AWS SDK on command line. I made a tiny script to read the adresses file (.txt) line by line and execute a send mail command
#! /bin/bash
file='./test-list.txt'
from='sender#domain.com'
for line in $(<$file)
do
#send mail
aws ses send-templated-email --source=$from --destination=$line --template 'test' --template-data ""
done
Script returned the error message :
Error parsing parameter '--destination': Expected: '=', received: '#' for input:
To:recipient#domain.com
Now I'm not the bash king, but I've tried different parameter formulations and nothing got me rid of the error.
each line from the input file is a correct email address, and this looks like a parsing issue, but I don't get it.
any ideas ? It would help a ton :)
You need to use the correct format for destination from https://docs.aws.amazon.com/cli/latest/reference/ses/send-templated-email.html#options
Example using send-email:
aws ses send-email --from "example.com" --destination "ToAddresses=${line}" --text "hello world!" --subject "test"
Example like the one given:
aws ses send-templated-email --source $from --destination "ToAddresses=${line}" --template "test" --template-data ""

AWS Cli: How to capture error to a variable instead of printing in the console

I'm trying to do prepare a script (.bat /.sh) with multiple commands and one of them is AWS Cli, and output of the execution has to be taken to a variable.
If the command is executed succesfully, it is returning the output that is expected, otherwise error is printing on console rather than to variable.
Any leads on this would be appreciated
Try below to redirect your standard error to the standard output and then store the standard output into the variable. This way you always get both so you can use $? to identify if the output is of type stderr or stdout
aws cli return codes
get_user=$(aws iam get-user --user-name johnDoe 2>&1)
echo $?
echo "$get_user"
255
An error occurred (NoSuchEntity) when calling the GetUser operation: The user with name johnDoe cannot be found.

put-gateway-response fails when --response-parameters option is set

I'm trying to set some custom API Gateway responses using aws cli. This is the command I'm using (only the related parameter):
aws apigateway put-gateway-response --response-parameters method.response.header.Access-Control-Allow-Origin='"'"'*'"'"'
The complete command is:
aws apigateway put-gateway-response --rest-api-id w1s3nc4dxd --response-type UNAUTHORIZED --status-code 401 --response-parameters method.response.header.Access-Control-Allow-Origin='"'"'*'"'"' --response-templates '{ "application/json": "{\"errorcode\":401,\"message\":$context.error.messageString}" }' --region eu-west-1
And it fails with:
An error occurred (BadRequestException) when calling the PutGatewayResponse operation: Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: method.response.header.Access-Control-Allow-Origin]
If it is executed without that param, everything works properly. I have also tried with the json format and same result.
--response-parameters '{"method.response.header.Access-Control-Allow-Origin":"'"'*'"'"}'
Any insight? Thanks in advance.
--- EDIT
Just for an extra clarification. This fails with all kind of response-parameters, this is not only involving Access-Control-Allow-Origin header.
I believe the format for Gateway Response parameters should be gatewayresponse.header.[name]. That will be the map key (destination), and the value (source) is either a static value (like you have) or a mapping expression to method.request.(path|querystring|header).[name] or stageVariables.[name] or context.[name]
Try using
--response-parameters '{"gatewayresponse.header.Access-Control-Allow-Origin":"'"'*'"'"}', it worked for me

Not able to get Amazon SNS logs

Below is the log stream I am getting with the CLI command :
And I am also getting the log streams as below:
But while accessing a log stream I am getting the below error:
So could you please help me where I am wrong or why the error is coming. Thanks in advance.
Try passing the values for log stream name and group name as double quoted strings, may be the params are not getting passed correctly