Why I get error usage command amazon cli? - amazon-web-services

¿How are you?
I'm trying to use this command in Amazon CLI:
aws autoscaling describe-launch-configurations \
--query "LaunchConfigurations[?contains(LaunchConfigurationName,'Extra')].LaunchConfigurationName\
| sort_by(LaunchConfigurations, &CreatedTime)[0].[CreatedTime,LaunchConfigurationName]
But I have an error:
In function sort_by(), invalid type for value: None, expected one of: ['array'], received: "null"
In the first part, I get a list of Launch configuration on Amazon EC2. Why in sort_by, I receive a null output?
When I execute the command without sort_by, I don't have any problem....

if your list returned by the query contains no results. the sort command will respond 'null'

Related

AWS CLI doesn't show output

I'm running into a weird situation where the aws cli doesn't show output at all. I tried running bad commands and it would show the expected error message but when I run a valid command such as: aws s3api list-buckets --profile prod it doesn't show anything, it just starts new line.

Not able to Create Contact flow with lex bot

Trying to migrate contact flow from one instance to other able to migrate simple flow but issue is when I tried with lex bot not able to migrate contact flow.
aws connect describe-contact-flow --instance-id <value> --contact-flow-id <value> --region us-east-1
aws connect create-contact-flow --instance-id <value> --name test_flow --type AGENT_TRANSFER --region 'us-east-1' --content "{\"Version\":\"2019-10-30\",\"StartAction\":\"cd60c6aa-6229-4a47-81ae-bef78a528590\",\"Metadata\":{\"entryPointPosition\":{\"x\":15,\"y\":23.99998474121091},\"snapToGrid\":false,\"ActionMetadata\":{\"bbb8a214-1f5c-4534-bfe5-6bf5f0aab9a0\":{\"position\":{\"x\":685,\"y\":132}},\"d76376f8-9b97-42dc-8b96-60167fd5f7a2\":{\"position\":{\"x\":351,\"y\":15}},\"cd60c6aa-6229-4a47-81ae-bef78a528590\":{\"position\":{\"x\":194,\"y\":197.3333282470703},\"useDynamic\":false},\"e36919ca-8fe7-4797-8c7e-6524acd838f8\":{\"position\":{\"x\":446,\"y\":208},\"conditionMetadata\":[],\"useDynamic\":false,\"dynamicMetadata\":{},\"useLexBotDropdown\":true,\"useDynamicLexBotArn\":false,\"lexV2BotName\":\"jenkinsbooktrip\"}}},\"Actions\":[{\"Identifier\":\"bbb8a214-1f5c-4534-bfe5-6bf5f0aab9a0\",\"Type\":\"DisconnectParticipant\",\"Parameters\":{},\"Transitions\":{}},{\"Identifier\":\"d76376f8-9b97-42dc-8b96-60167fd5f7a2\",\"Parameters\":{\"FlowLoggingBehavior\":\"Enabled\"},\"Transitions\":{\"NextAction\":\"bbb8a214-1f5c-4534-bfe5-6bf5f0aab9a0\",\"Errors\":[],\"Conditions\":[]},\"Type\":\"UpdateFlowLoggingBehavior\"},{\"Identifier\":\"cd60c6aa-6229-4a47-81ae-bef78a528590\",\"Parameters\":{\"Text\":\"hi welcome\"},\"Transitions\":{\"NextAction\":\"e36919ca-8fe7-4797-8c7e-6524acd838f8\",\"Errors\":[],\"Conditions\":[]},\"Type\":\"MessageParticipant\"},{\"Identifier\":\"e36919ca-8fe7-4797-8c7e-6524acd838f8\",\"Parameters\":{\"Text\":\"welcome\",\"LexBot\":{\"Name\":\"jenkinsbooktrip\",\"Region\":\"us-east-1\",\"Alias\":\"$LATEST\"}},\"Transitions\":{\"NextAction\":\"bbb8a214-1f5c-4534-bfe5-6bf5f0aab9a0\",\"Errors\":[{\"NextAction\":\"bbb8a214-1f5c-4534-bfe5-6bf5f0aab9a0\",\"ErrorType\":\"NoMatchingError\"},{\"NextAction\":\"d76376f8-9b97-42dc-8b96-60167fd5f7a2\",\"ErrorType\":\"NoMatchingCondition\"}],\"Conditions\":[]},\"Type\":\"ConnectParticipantWithLexBot\"}]}"
An error occurred (InvalidContactFlowException) when calling the CreateContactFlow operation: None,
when trying without lex parameter it working fine able to create but with lex its through an error I am using aws cli command
I have had the same issue generally with connect. When the content is less than ~1500-2000 characters, the Api works perfectly. Once the contact flow content grows beyond that, you start getting those errors.
Yes that's right need to skip $ symbol and it will work fine.

In AWS, How can i find if a given vpc id is a valid one using the aws cli?

I'm using the following in my jenkins file
sh aws ec2 describe-vpcs --vpc-ids ${VPC_ID} --query 'Vpcs[*].[State]' --output text
If it is valid is gives me available
else it gives me the error :
An error occurred (InvalidVpcID.NotFound) when calling the DescribeVpcs operation: The vpc ID 'vpc-0xx0xx0xx' does not exist
Is there a way to gracefully catch the response using this method ?
I think you can use filter rather than --vpc-ids.
aws ec2 describe-vpcs --filters Name=vpc-id,Values="id" --query 'Vpcs[*].[State]'
It will not give an error just empty.
Furthermore, this is my modified one. Since the vpc-id is unique, you don't need [*] when you set the vpc-id and just select the first one and no bracket for state.
aws ec2 describe-vpcs --filters Name=vpc-id,Values="id" --query 'Vpcs[0].State'
Then, the result looks like
"avalilable"
or
null

Parse Error Creating AWS Event From the CLI

I'm trying to create an event using the AWS CLI. When I issue this command:
aws events put-targets --rule Rotate-Old-Access-Keys-Notification-Scheduler --targets "Id"="1","Arn"="arn:aws:lambda:us-east-1:12345678910:function:rotate-old-access-keys-notification-sender" --profile=lab
I get the error:
Error parsing parameter '--targets': Expected: '=', received: 'EOF' for input:
Id
^
How can I fix this command so that it works?
There is an issue while you are trying to parse profile to your command. Below command should work.
aws events put-targets --rule Rotate-Old-Access-Keys-Notification-Scheduler --targets "Id"="1","Arn"="arn:aws:lambda:us-east-1:12345678910:function:rotate-old-access-keys-notification-sender" --profile lab

aws ec2 describe-instance-status filter by tag not working

I am trying to get all ec2 instance that have schedules events and filter by a tag name. But the filter by tag throws an error.
I am trying the below command:
aws ec2 describe-instance-status --filters "Name=tag:Name,Values=*xyz*"
The above command throws:
An error occurred (InvalidParameterValue) when calling the DescribeInstanceStatus operation:
The filter 'tag:Name' is invalid
However when I run the same filer on describe-instances, it works fine:
aws ec2 describe-instances --filters "Name=tag:Name,Values=*xyz*"
The above command returns the ec2 instances as expected.
It happens on boto3 as well.
Please help on this.
The filters that are accepted by describe-instance-status are documented here. As can be seen, filtering by tag is not an option. You will probably need to firstly get the list of instance-ids using describe-instances and filtering by tag, and then for each of these instance-ids, find the instance status.