Get SQS Queue Name from existing queue ARN in CloudFormation - aws-cloudformation

I have an SQS Queue ARN as an input to my CloudFormation template, How do I reference Queue Name or URL from Queue ARN?
In other words, how do I get a CloudFormation Logical Queue from the ARN?(so that I can use GetAtt to reference all the attributes)

Assuming you can't pass in the name from whatever is creating the queue, then you can get the queue name from the arn. Use Fn::Split to split the arn on colons. Then use Fn::Select to select the last string in the list. This will be something like
{ "Fn::Select" : [ "5", { "Fn::Split": [":", {"Fn::Sub": "QueueArn"}]}] }
See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html for a full list of the functions you can use.

Related

Terraform: add a message to queue

I create queue inside storage by the following way:
resource "azurerm_storage_queue" "myqueue" {
name = "myqueue"
storage_account_name = "${azurerm_storage_account.sto1.name}"
}
but for this queue I want to add init message (it's like a marker, when I sync with external resource last time and need to get data from the last execution). How can I configure it in terraform file?
This sounds like a use case for remote-exec.
Generally when using remote-exec, using a null provider is recommended. This lets you have closer control over what triggers the provider, rather than being dependent on the logic of the cloud service you're integrating it with.

How can I add a subscription in Appsync which is invoked by a lambda?

I know that subscription in Appsync works with mutation, which means whenever mutation gets invoked, subscription is also invoked which sends the message to all the subscribers.
What I want is that if there is any way, I can basically sends a message to the user directly from lambda using Appsync or any other way in real time? That is, I don't want user to refresh the page.
The use case can be, say, I have a standalone lambda which runs every hour and wants to notify users every hour about something. It is not part of any mutation or query.
You can attach a None DataSource to a mutation and send the information required for the subscription to be triggered within the mutation arguments.
for example let's assume you have the following schema
type Book {
bookId: Int
}
input BookInput {
bookId: Int
}
type mutation {
triggerBookUpdate(input: BookInput!): Book
}
type subscription {
onBookUpdate(bookId: Int!): Book
#aws_subscribe(mutations: ["triggerBookUpdate"])
}
then you attach the None DataSource to the resolver for the TriggerBookUpdate field and provide the following Request Mapping Template
#**
Resolvers with None data sources can locally publish events that fire
subscriptions or otherwise transform data without hitting a backend data source.
The value of 'payload' is forwarded to $ctx.result in the response mapping template.
*#
{
"version": "2017-02-28",
"payload": $utils.toJson($context.arguments.input)
}
and the Response Mapping Template
$util.toJson($ctx.result)
for more information check this Documentation

Is there a way to capture the name of a task that has been executed in SnapLogic?

We have a lot of triggered Tasks that run on the same pipelines, but with different parameters.
My question regarding this - is there a possible way, like a function or an expression to capture the name of the triggered task so that we could use the information while writing the reports and e-mails of which Task started the error pipeline. I can't find anything even close to it.
Thank you in advance.
This answer addresses the requirement of uniquely identify the invoker task in the invoked pipeline
For triggered tasks, there isn't anything provided out of the box by SnapLogic. Although, in case of ULTRA tasks you can get $['task_name'] from the input to the pipeline.
Out of the box, SnapLogic provides the following headers that can be captured and used in the pipeline being initiated by the triggered task. These are as follows.
PATH_INFO - The path elements after the Task part of the URL.
REMOTE_USER - The name of the user that invoked this request.
REMOTE_ADDR - The IP address of the host that invoked this request.
REQUEST_METHOD - The method used to invoke this request.
None of these contains the task-name.
In your case, as a workaround, to uniquely identify the invoker task in the invoked pipeline you could do one of the following three things.
Pass the task-name as a parameter
Add the task-name in the URL like https://elastic.snaplogic.com/.../task-name
Add a custom header from the REST call
All the three above methods can help you capture the task-name in the invoked pipeline.
In your case, I would suggest you go for a custom header because the parameters you pass in the pipeline could be task-specific and it is redundant to add the task-name again in the URL.
Following is how you can add a custom header in your triggered task.
From SnapLogic Docs -
Custom Headers
To pass a custom HTTP header, specify a header and its value through the parameter fields in Pipeline Settings. The
request matches any header with Pipeline arguments and passes those to
the Task, while the Authorization header is never passed to the
Pipeline.
Guidelines
The header must be capitalized in its entirety. Headers are case-sensitive.
Hyphens must be changed to underscores.
The HTTP custom headers override both the Task and Pipeline parameters, but the query string parameter has the highest precedence.
For example, if you want to pass a tenant ID (X-TENANT-ID) in a
header, add the parameter X_TENANT_ID and provide a default or leave
it blank. When you configure the expression, refer to the Pipeline
argument following standard convention: _X_TENANT_ID. In the HTTP
request, you add the header X-TENANT-ID: 123abc, which results in the
value 123abc being substituted for the Pipeline argument X_TENANT_ID.
Creating a task-name parameter in the pipeline settings
Using the task-name parameter in the pipeline
Calling the triggered task
Note: Hyphens must be changed to underscores.
References:
SnapLogic Docs - Triggered Tasks
I'm adding this as a separate answer because it addresses the specific requirement of logging an executed triggered task separate from the pipeline. This solution has to be a separate process (or pipeline) instead of being part of the triggered pipeline itself.
The Pipeline Monitoring API doesn't have any explicit log entry for the task name of a triggered task. invoker is what you have to use.
However, the main API used by SnapLogic to populate the Dashboard is more verbose. Following is a screenshot of how the response looks on Google Chrome Developer Tools.
You can use the invoker_name and pipe_invoker fields for identifying a triggered task.
Following is the API that is being used.
POST https://elastic.snaplogic.com/api/2/<org snode
id>/rest/pm/runtime
Body:
{
"state": "Completed,Stopped,Failed,Queued,Started,Prepared,Stopping,Failing,Suspending,Suspended,Resuming",
"offset": 0,
"limit": 25,
"include_subpipelines": false,
"sort": {
"create_time": -1
},
"start_ts": null,
"end_ts": null,
"last_hours": 1
}
You can have a pipeline that periodically fires this API then parses the response and populates a log table (or creates a log file).

pause the template execution for a few minutes

I have a cloudformation template that works correctly. It initiates an elastic server along with cloud-trail.
datameetgeobk.s3.amazonaws.com/cftemplates/audit_trail.yaml
I have to wait for 10 minute to get the endpoint. The endpoint is used in Lambda function that is part of another template.
stream logs to elastic using cloudformation template
Is there WaitCondition in cloudformaton that I can use before joining these 2 templates?
Yes, there is a WaitCondition that uses properties like Count, Handle, Timeout.
More info about the same is Here
Example Code
Declare an `AWS::CloudFormation::WaitConditionHandle resource in the stack's template
"myWaitHandle" : {
"Type" : "AWS::CloudFormation::WaitConditionHandle",
"Properties" : {
}
}

IBM Watson Conversation: How to dynamically create context variables?

In IBM Watson Conversation, context variables can be used to carry information. A value can be derived from the evaluation of expressions as shown:
"context": {
"mycity": "<? entities['city'].value ?>"
}
What I tried is to dynamically compose the variable name:
"context": {
"my<? #animals ?>": "my new value"
}
However, the expression in the variable name is not evaluated. How can I define a variable name based on available data such as intents, entities or other context variables?
One solution seems to be to do it in the application:
Receive response object including all the metadata.
Extract necessary data
Compose context object to be passed back into Watson Conversation for next message processing. Create new variables as part of this preparation.
Call message API with context object which includes new variable.
New variable is available during Watson Conversation-internal processing.