How to read ami id dynamically from aws using cloudformation - aws-cloudformation

I am automating the cloudformation template by reading latest ami id from the corresponding region. I was able to achieve this by using terraform.
In terraform, we have data sources to query and filter the aws ami-id. similarly do we have any sources in cloudformation to query and filter the private aws ami-id?
In terraform, we can get the ami id using the below
data "aws_ami" "example" {
executable_users = ["self"]
most_recent = true
name_regex = "^myami-\\d{3}"
owners = ["self"]
filter {
name = "name"
values = ["myami-*"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
Whereas, could anyone help me to do the same using cloudformation template?
Thanks in advance :)

This walkthrough shows you how to create a custom resource and associate a Lambda function with it to look up AMI IDs.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-custom-resources-lambda-lookup-amiids.html

Related

ExtractTopic Transformation in Kafka

My data is like below,
{"empid"="100","empname="test"}
Now, my transform is,
'transforms' ='IndexName',
'transforms.IndexName.type' = 'io.confluent.connect.transforms.ExtractTopic$Value',
'transforms.IndexName.field' = 'test',
'transforms.IndexName.skip.missing.or.null' = 'true'
I am creating the sink connector for elasticsearch. while using the above transform I can create the index name like "test". But I want to customize the index name like "test100". is it possible?
You would need to use more than one transform to modify test to testblah
Add a RegexRouter after the extraction to update the topic name with static content
"transforms" = "IndexName,AddSuffix"
"transforms.IndexName.type" = ...
...
"transforms.AddSuffix.type" = ...
...
If you're trying to pull the empid=100 field, there is no current transform that can extract & concatenate more than one field, and I would question your design choices for having one Elasticsearch index per empid

Azure DevOps queryByWiql does not query correct project

I would like to know if there is a way for the Azure DevOps dashboard widget to know what project it belongs to or resides in. For example, I have 2 projects. The widget should be able to differentiate between the two, fetch different data, but ultimately do the same thing.
I took a look at the API reference
Here is what I tried:
var projectId = VSS.getWebContext().project.id;
var query = {
query: "SELECT [System.Id] FROM WorkItem WHERE [System.WorkItemType] = 'Epic' AND [System.State] NOT IN ('Closed','Completed','Resolved','Removed', 'Done')"
};
witClient.queryByWiql(query, projectId).then(
function (epics) {
epics.workItems.forEach(epic => {
...
However, I am getting back Epics from projects that the dashboard is not under. Our org has several projects/products that have their own WorkItems.
I verified that the projectId variable maps to the correct project, I just don't know why my query returns Epics that do not belong to the correct project...
I want to create a widget that determines which project it belongs to, and fetch data for only that project.
When you want to have the data of a specific project, be sure that you also refer to it in the WIQL query. You can do this by adding [System.TeamProject] = #project to your query.
var projectId = VSS.getWebContext().project.id;
var query = "SELECT [System.Id] FROM WorkItem WHERE [System.WorkItemType] = 'Epic' AND [System.State] NOT IN ('Closed','Completed','Resolved','Removed', 'Done') AND [System.TeamProject] = #project";
witClient.queryByWiql({ query: query }, projectId).then(function (epics) {
// do your stuff here
});

Update CreatedBy(System.CreatedBy) workitem field in VSTS 2017

We are unable to update CreatedBy(System.CreatedBy) workitem field in VSTS 2017 using rest API. The user has been added to "Project Collection Service Accounts" VSTS group in order to bypass the rules while updating the workitem.
Link: https://github.com/Microsoft/vsts-dotnet-samples/blob/master/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs#L271
public WorkItem UpdateWorkItemUsingByPassRules(int id)
{
JsonPatchDocument patchDocument = new JsonPatchDocument();
patchDocument.Add(
new JsonPatchOperation() {
Operation = Operation.Add,
Path = "/fields/System.CreatedBy",
Value = "Foo <Foo#hotmail.com>"
}
);
VssConnection connection = Context.Connection;
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result;
return result;
}
When validateOnly parameter is set to true instead on null, then the result output holds the updated created by value.
System.CreatedBy field can only be modified on work item creation. If the work item has multiple revisions, System.CreatedBy can not be changed by bypassing rule.
You can also find it in make an update bypassing rules:
NOTE: System.CreatedBy and System.CreatedDate can only be modified
using bypass rules on work item creation, i.e. the first revision of a
work item.
Since System.CreatedBy and System.CreatedDate record who and when did a work item created, it can only be updated when you create the work item.

ArangoDB create Vertex REST API without knowing the vertex id's

Is there a way to create with ArangoDB an Edge with REST API without knowing the Vertex ids? With a query to find the vertexs and link them?
Like this with OrientDB: create edge Uses from (select from Module where name = 'm2') to (select from Project where name = 'p1')
I don't want to query via REST the two vertex before, and after create the Edge. I don't want to use Foxx also.
Perhaps with AQL?
Thanks.
Yes, it is doable with a single AQL query:
LET from = (FOR doc IN Module FILTER doc.name == 'm2' RETURN doc._id)
LET to = (FOR doc IN Project FILTER doc.name == 'p1' RETURN doc._id)
INSERT {
_from: from[0],
_to: to[0],
/* insert other edge attributes here as needed */
someOtherAttribute: "someValue"
}
INTO nameOfEdgeCollection

Moped: get id after inserting

When I use mongo-ruby-driver and I insert new document it returns generated '_id':
db = MongoClient.new('127.0.0.1', '27017').db('ruby-mongo-examples')
id = db['test'].insert({name: 'example'})
# BSON::ObjectId('54f88b01ab8bae12b2000001')
I'm trying to get the '_id' of a document after doing an insertion using Moped:
db = Moped::Session.new(['127.0.0.1:27017'])
db.use('ruby-mongo-examples')
id = db['coll'].insert({name: 'example'})
# {"connectionId"=>15, "n"=>0, "syncMillis"=>0, "writtenTo"=>nil, "err"=>nil, "ok"=>1.0}
How I get the id using Moped?
Update:
I also try use safe mode but it doesn't work:
db = Moped::Session.new(['127.0.0.1:27017'])
db.use('ruby-mongo-examples')
db.with(safe: true) do |safe|
id = safe['coll'].insert({name: 'example'})
# {"connectionId"=>5, "n"=>0, "syncMillis"=>0, "writtenTo"=>nil, "err"=>nil, "ok"=>1.0}
end
After inserting/saving, the returned object will have a property inserted_id which is a BSON::ObjectId:
# I'm using insert_one
result = safe['coll'].insert_one({name: 'example'})
result.methods.sort # see list of methods/properties
result.inserted_id
result.inserted_id.to_s # convert to string
From this issue:
It would be nice, but unfortunately Mongo doesn't give us anything
back when inserting (since it's fire and forget), and when in safe
mode it still doesn't give the id back if it generated it on the
server. So there really isn't any possible way for us to do this
unless it was a core feature in MongoDB.
Your best bet would be to generate the id before inserting the document:
document = { _id: Moped::BSON::ObjectId.new, name: "example" }
id = document[:_id]