aws rds describe-db-clusters --db-cluster-identifier with wildcard - amazon-web-services

I am looking to run aws rds describe-db-clusters --db-cluster-identifier CLI command with wildcard. Something like:
aws rds describe-db-clusters --db-cluster-identifier prod% --region us-east-1
I want to retrieve info about all the RDS clusters whose name start with prod. When I run the above cli command, I get an error
An error occurred (InvalidParameterValue) when calling the DescribeDBClusters operation: Invalid database cluster identifier: prod%
Is there a way (via CLI or Py Code) to get the list of all RDS Clusters whose name start with prod?
Thanks

Related

Failed to create Elasticache redis cluster

I was using the following command to create a Elasticache redis cluster via CLI but it always failed at the end, when I switch to the AWS console I can first see the creating status but after a while it will always fail, is there a way to view the creation logs in AWS console?
aws elasticache create-replication-group --cache-subnet-group group-name --engine redis --engine-version 6.x --security-group-ids security-group-id --num-node-groups 22 --replicas-per-node-group 2 --cache-parameter-group-name parameter-group-name --auto-minor-version-upgrade --replication-group-id some-group-id --replication-group-description 'some description' --cache-node-type cache.r6g.2xlarge --region some-region --automatic-failover-enabled

Create security group at CLI, getting InvalidVpcID.NotFound The vpc ID does not exist

Trying to issue:
$ aws ec2 create-security-group --group-name Grp1 --description Grp1 --vpc-id vpc-0e6f748e8c01534bc
But I get
An error occurred (InvalidVpcID.NotFound) when calling the CreateSecurityGroup operation:
The vpc ID 'vpc-0e6f748e8c01534bc' does not exist
That vpc does exists, but it isn't being recognized.
It is in a different region.
I can't specify region in the command.
How do I get around that?
When you do some command on the aws cli, you can submit the region option as follows.
aws cli <some code> --region <region>
The cli options are listed in the aws documentation.

How can I get the RDS endpoint for use in Userdata

I am trying to get the RDS endpoint to use in user data with cli but unable to figure it out.
I need to get the RDS endpoint to inject into a php file but when I try the following I get:
Unable to locate credentials. You can configure credentials by running "aws configure".
I am building the ec2 and vpc using CLI and need to be able to get RDS endpoint as part of the Userdata.
I tried the following on the EC2 instance itself and I get the above error.
aws rds --region ca-central-1 describe-db-instances --query "DBInstances[*].Endpoint.Address"
Even if I am able to resolve that, I need to be able to get the endpoint to pass as part of the userdata. Is that even possible?
The Unable to locate credentials error says that the AWS Command-Line Interface (CLI) does not have any credentials to call the AWS APIs.
You should assign a role to the EC2 instance with sufficient permission to call describe-db-instances on RDS. See: IAM Roles for Amazon EC2
Then, your User Data can include something like:
#!
RDS=`aws rds --region ca-central-1 describe-db-instances --query "DBInstances[*].Endpoint.Address"`
echo >file $RDS
Or pass it as a parameter:
php $RDS
I have it working with this -
mac=curl -s http://169.254.169.254/latest/meta-data/mac
VPC_ID=curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$mac/vpc-id
aws rds describe-db-instances --region us-east-2 | jq -r --arg VPC_ID "VPC_ID" '.DBInstances[] |select (.DBSubnetGroup.VpcId=="'$VPC_ID'") | .Endpoint.Address'

AWS ec2 describe Instance not working

aws ec2 describe-instance-status --instance-id "*****"
This cli command works only for the region where you run this command, If i want to check Instance state of other location, unable to identify instance ID
Error: An error occurred (InvalidInstanceID.NotFound) when calling the DescribeInstanceStatus operation: The instance ID '***********' does not exist
If you wish to run the query in another region, simply define this when running the command:
For example, to run in us-west-2:
aws --region us-west-2 ec2 describe-instances --instance-ids <ids>

AWS Aurora: how to restore a db cluster snapshot via aws cli?

It's pretty easy via the console but I need to do the same from CLI.
First I created a db snapshot:
aws rds create-db-cluster-snapshot \
--db-cluster-snapshot-identifier $SNAPSHOT_ID \
--db-cluster-identifier $CLUSTER \
CLUSTER contains only one writer instance
I did not use create-db-snapshot method because it throwned an error
A client error (InvalidParameterValue) occurred when calling the CreateDBSnapshot operation: The specified instance is a member of a cluster and a snapshot cannot be created directly. Please use the CreateDBClusterSnapshot API instead.
It works:
aws rds create-db-cluster-snapshot \
--db-cluster-snapshot-identifier $SNAPSHOT_ID \
--db-cluster-identifier $CLUSTER \
{
"DBClusterSnapshot": {
"Engine": "aurora",
"SnapshotCreateTime": "2016-12-08T11:48:07.534Z",
....
}
So, I wanted to restore a new Aurora cluster from the snapshot, then I tried:
aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier from-snap2 \
--db-snapshot-identifier snap2 \
A client error (DBSnapshotNotFound) occurred when calling the RestoreDBInstanceFromDBSnapshot operation: DBSnapshot not found: snap2
So I tried to restore with:
aws rds restore-db-cluster-from-snapshot \
--db-cluster-identifier from-snap2 \
--snapshot-identifier snap2 \
--engine aurora \
--vpc-security-group-ids $PREPROD_SG \
--db-subnet-group-name my-db-subnet-group \
It works...
{
"DBCluster": {
...
"EngineVersion": "5.6.10a",
"DBClusterIdentifier": "from-snap2",
...
"DBClusterMembers": [],
...
}
But why the cluster does not contain any Aurora instance?
Where is the mistake?
This is very counterintuitive. If you restore a cluster from a snapshot, but there are no member instances in the cluster, what operation has actually succeeded? It seems as if all this does is create some kind of logical entity, maybe the backing store, but no instances.
Strange. But, the API documentation does show the cluster members as an empty set in the example response.
<DBClusterMembers/>
So it seems you create a cluster, as you did, then you apparently create instances in the cluster, as explained in an AWS Forum post:
aws rds create-db-instance --db-instance-identifier my-instance --db-instance-class db.r3.large --engine aurora --db-subnet-group-name default-vpc-xxxxxx --db-cluster-identifier my-instance-cluster
https://forums.aws.amazon.com/thread.jspa?messageID=688727
Apparently the console encapsulates multiple API requests behind the same action.
Response from AWS Support:
This is a known issue when using the API calls and our engineers are working on it. Even if the cluster is visible on AWS Console after the creation via CLI it will not create any instance automatically in your Aurora Cluster. In this case, you will need to create a db-instance and associate it to your newly restored cluster. When performing this Action on the AWS Console a new instance is automatically created for the cluster, but the action from the CLI uses separated API calls.
The following documentation provides detailed information on how to create a DB instance:
http://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html
You can describe your clusters using the AWS Console or using the CLI:
http://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html
Here is a command line example that creates the instance and associate it to a fictional cluster:
aws rds create-db-instance --engine aurora --db-cluster-identifier yourauroraclusteridentifier --db-instance-class db.t2.medium --db-instance-identifier yourinstanceidentifier
In my case, --db-cluster-identifier is the cluster created from the cluster snapshot.
If you create with aws rds create-db-cluster-snapshot then you can't restore with aws rds restore-db-instance-from-db-snapshot. The first creates a DB snapshot and the second restores a Cluster snapshot, different types.
From your question it looks like your restore is correct, maybe you need --database-name specified. Also you could try the restore with only the required parameters, i.e no vpc sg or DB subnet.