How to Query Route53 hosted zone to check for an existing record set? - amazon-web-services

I am new to amazon Route53. As of now, I am able to create a hosted zone and a resource record set in my amazon account. But now I want to search whether a record set already exists in my hosted zone. For Example
Hosted zone "abc.com" and it has two-record set in it.
A.abc.com
B.abc.com
Now I want to query my hosted zone and find out whether A.abc.com already exists in the abc.com.
So, is there any API that I can use where I can pass my amazon credentials and my amazon hostedzone and the searched "record set" and then I can get the result back whether that record set already exists. Kindly guide me.
After research, I found out that there is "ListResourceRecordSet" which will give me the list back for a particular zone. But I don't want the list I just want to check whether the entry already exists.

I have been able to perform this check efficiently using the ListResourceRecordSet API method, and the name and maxitems parameters. You haven't specified how you are accessing the API, so I'm going to explain this using the standard AWS REST API.
Given your example:
Call the API passing A.abc.com as the name parameter and 1 as the maxitems parameter. Your request will look like this: https://route53.amazonaws.com/2013-04-01/hostedzone/{YOUR_HOSTED_ZONE_ID}/rrset?name=A.abc.com.&maxitems=1
Note that I've added a trailing dot (".") to the end of the resource name A.abc.com. The API reference indicates that it may affect result sort order so I add it just in case.
You will get back an XML result in this format:
<?xml version="1.0"?>
<ListResourceRecordSetsResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<ResourceRecordSets>
<ResourceRecordSet>
<Name>A.abc.com.</Name>
<Type>A</Type>
<TTL>3600</TTL>
<ResourceRecords>
<ResourceRecord>
<Value>SOME_IP_ADDRESS</Value>
</ResourceRecord>
</ResourceRecords>
</ResourceRecordSet>
</ResourceRecordSets>
<IsTruncated>true</IsTruncated>
<NextRecordName>B.abc.com.</NextRecordName>
<NextRecordType>A</NextRecordType>
<MaxItems>1</MaxItems>
</ListResourceRecordSetsResponse>
Now you're going to have to do some parsing. Check the result to see if there is one ResourceRecordSet and if its Name property matches the name of the resource record you are looking for (you probably want to do a case-insensitive compare of the two values). Keep in mind that the Name property has that trailing period (".") at the end, so add it to the name you're searching for before doing the comparison.
If there is exactly one resource record set and the name matches the one you are looking for, it exists. If either one of those checks fails, then it does not exist.
Granted, this isn't as simple as a GetResourceRecordSet operation would be, but at least it keeps you from having to query the entire zone and parse a bunch of records. You also won't run into the long delay or throttling issues that you may using the CLI --query option.
There does not appear to be a way to use this method with the AWS CLI as it lacks a --name parameter for some reason. I can vouch for the fact that the JavaScript SDK will allow you to do this using the StartRecordName parameter.

There is no way to filter the API call, but there is a way to filter the data returned. Using the CLI you can do this with the --query option.
From the documentation: "To view all the resource record sets of a particular name, use the --query parameter to filter them out. For example:"
aws route53 list-resource-record-sets --hosted-zone-id Z2LD58HEXAMPLE --query "ResourceRecordSets[?Name == 'A.abc.com']"

Related

How to Search through AWS Route53 Domain records through boto3 sdk?

I want a webpage listing all the Records in a hosted zone from AWS Route 53 and use all the operations like Search, Add and Edit on those records.
Till now, I am able to list all the records using list_resource_record_sets(), also able to Add and Edit a record
using change_resource_record_sets().
But the problem is with searching. I am not able to find any parameter or function for Searching through all the records and get all matching results. The searching should be like it is in AWS console.
How to implement this searching part?
you already found it. It's the list_resource_records_sets
https://docs.aws.amazon.com/Route53/latest/APIReference/API_ListResourceRecordSets.html
or boto:
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/route53.html#Route53.Client.list_resource_record_sets
you can pass in additional arguments that narrow down what you are listing. Thisis what the console does.
response = client.list_resource_record_sets(
HostedZoneId='string',
StartRecordName='string',
StartRecordType='SOA'|'A'|'TXT'|'NS'|'CNAME'|'MX'|'NAPTR'|'PTR'|'SRV'|'SPF'|'AAAA'|'CAA'|'DS',
StartRecordIdentifier='string',
MaxItems='string'
)

sort GCP billing data by metadata tags

I'm a little confused in GCP with tags, labels and metadata and I do not find how to sort my billing informations by the metadata tags i set for every objects in the storage.
I have added a metadata tagging process which gives the id of the account that uploads a file through signed url headers or through blobs uploads. Then I launch requests on the billing with big query.
...but I do not see my tags in the "labels" field of the exports
How can I enable metadata tags sorting on billing exports ?
Thank you for your help
Metadata identifies properties of the object, as well as specifies how the object should be handled when it's accessed. Metadata exists as key:value pairs. Metadata has fixed-key metadata, also Custom metadata, that is to say you can add any key:value value in your metadata.
If a group of GCP resources has the same key:value in its custom mateadata, who can take this key:value as the Bucket labels are key:value that allow you to group your buckets along with other Google Cloud resources such as virtual machine instances and persistent disks.
Tagging actually is like a condition, for example, I want to query those resources which have a specific key:value, then the service will look for those resources which have a label the same as key value.
May the explanation is still not easy to understand, let me use sql query as an example.
SELECT GCP.Resources.Cost FROM GCP.Resources WHERE GCP.Resources.Lable = Tag GROUP BY GCP.Resources.Metadata
GCP billing doesn't break down Bucket costs by object.
It simply tells you how much the whole bucket cost you.
If you want to calculate what portion of your Bucket bill can be attributed to an object you will need to know when the object was uploaded and how big it was, and then do math to calculate the portion of the cost it's responsible for.
You would need to turn on logging on the buck to get that data.
Tags data is available in both the Standard usage cost export and the Detailed usage cost export
SELECT
invoice.month AS invoice_month,
tag.value AS cost_center,
ROUND((SUM(CAST(cost AS NUMERIC))
+ SUM(IFNULL((SELECT SUM (CAST(c.amount AS NUMERIC))
FROM UNNEST(credits) AS c), 0))), 2)
AS net_cost
FROM `ivory-vim-309221.billing_export_dataset.gcp_billing_export_resource_v1_018ADD_3CEBBB_A4DF22`, UNNEST(tags) AS tag
WHERE tag.key = "cost_center" AND tag.namespace = "821092389413"
GROUP BY invoice.month, tag.value
ORDER BY invoice.month, tag.value;
https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables/standard-usage#tags

Get all items in DynamoDB with API Gateway's Mapping Template

Is there a simple way to retrieve all items from a DynamoDB table using a mapping template in an API Gateway endpoint? I usually use a lambda to process the data before returning it but this is such a simple task that a Lambda seems like an overkill.
I have a table that contains data with the following format:
roleAttributeName roleHierarchyLevel roleIsActive roleName
"admin" 99 true "Admin"
"director" 90 true "Director"
"areaManager" 80 false "Area Manager"
I'm happy with getting the data, doesn't matter the representation as I can later transform it further down in my code.
I've been looking around but all tutorials explain how to get specific bits of data through queries and params like roles/{roleAttributeName} but I just want to hit roles/ and get all items.
All you need to do is
create a resource (without curly braces since we dont need a particular item)
create a get method
use Scan instead of Query in Action while configuring the integration request.
Configurations as follows :
enter image description here
now try test...you should get the response.
to try it out on postman deploy the api first and then use the provided link into postman followed by your resource name.
API Gateway allows you to Proxy DynamoDB as a service. Here you have an interesting tutorial on how to do it (you can ignore the part related to index to make it work).
To retrieve all the items from a table, you can use Scan as the action in API Gateway. Keep in mind that DynamoDB limits the query sizes to 1MB either for Scan and Query actions.
You can also limit your own query before it is automatically done by using the Limit parameter.
AWS DynamoDB Scan Reference

EC2 Instance Search in API

In the AWS EC2 console on the web, there is a search box that allows you to search for instances by keyword. It appears that this searches many fields (such as hostname, tags, instance state, etc.) for the provided keyword.
Here is an example of searching for the keyword "running". The UI shows a filter named "search" with the search value "running". It appears that this returns instances in the "running" state but also instances named "running", with a tag value of "running", a hostname of "running", etc.
Is this functionality available through the API? The describe-instances API call has filters, but it appears as though there is no documented filter that matches this behaviour (which searches all fields instead of just the specified ones). I've tried a filter named "search" but that does not work.
There is no API equivalent that search all fields (eg state, name, tag). However, you could emulate this by retrieving details of ALL instances via the API and then having your app filter the results.
One way I think it can be done is using aws ec2 describe-instances (use corresponding API in your preferred language sdk) and do a regex to filter out the results.

Cheapest way to use AWS for simple response

What I wanted to achieve is pretty simple, if you send a request to some address, the response you get is a single integer number, like 13 for example. I think it is equivalent to hosting a .html page with single number on that page and then I can parse that string in my application. (It is a Unity game, using the WWW class to send the request.)
(This is actually a version number. If it is greater than what I stored in my app I would update it and then send another request to other place and retrieve something bigger)
I am looking for the cheapest way that can handle this. I planned to use AWS but confused what component should be use? S3? EC2? Lambda? CloudFront?
If you think doing this on a web hosting or Heroku or something else is better, I also wanted to hear about it.
To serve up a simple value, S3 should do the trick.
Create a bucket in the console, using lonely lowercase letters, digits, and dashes in the name. The name has to be globally unique among all of S3, so make up something unique. We'll call the bucket name example-bucket.
Create your file on your computer with the desired contents. If plain text, call it version.txt.
In the AWS console, select the bucket, and upload the file. While clicking through the "next" screens, put a check next to "make everything public" and accept the defaults. Upload the file.
Now, go to https://example-bucket.s3.amazonaws.com/version.txt in your browser and verify (using your actual bucket name. That's your download link.
Done. As long as you don't expect to handle over about 800 requests per second, this will do exactly what you want.
Review the S3 pricing, of course.
Although this question is suitable for Server Fault,
EC2 using nginx or apache web server will be sufficient.
Put Load balancer in front of EC2 instances.