AWS Step Function - how to receive input? - amazon-web-services

I have the below step function and I'm trying to pass the ARN to the StartProjectVersion step in the "test" variable using "ProjectVersionArn": "$.test". Every time I execute the step functions, StartProjectVersion fails with:
2 validation errors detected: Value '$.test' at 'projectVersionArn'
failed to satisfy constraint: Member must satisfy regular expression
pattern: (^arn:[a-z\d-]+:rekognition
How can I set the ARN using $.test? Thank you.

Parameters: For key-value pairs where the value is selected using a path, the key name must end in .$.
"ProjectVersionArn.$": "$.test"

Related

Regex error in cloudbuild.yaml file while passing project-id

I'm trying to run a dataflow job using cloud build
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args:
dataflow
jobs
run
google-template-job
--gcs-location=gs://dataflow-templates/latest/PubSub_Subscription_to_BigQuery
--parameters=inputSubscription='projects/$PROJECT_ID/subscriptions/messages'
--parameters=outputTableSpec="$PROJECT_ID:beam_samples.streaming_beam"
--staging-location=gs://cloudbuild-dataflow-testproject123456789-313307/tmp'
--region=us-central1
Every time I trigger the build I get the following error
ERROR: (gcloud.dataflow.jobs.run) INVALID_ARGUMENT: The template parameters are invalid.
- '#type': type.googleapis.com/google.dataflow.v1beta3.InvalidTemplateParameters
parameterViolations:
- description: 'Unmatched regex: ^projects\/[^\n\r\/]+\/subscriptions\/[^\n\r\/]+$'
parameter: inputSubscription
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/gcloud" failed: step exited with non-zero status: 1
My project id has a ' - ' in it so if I replace the $PROJECT_ID with the value of project id, I still get the same error, is there any workaround for this. I don't have any control over stopping the regex check since it's a google provided template.
How do I get past this
Got it. It's only a command interpreter issue. If you put single quote, you prevent any evaluation of the inside string.
In you case
--parameters=inputSubscription='projects/$PROJECT_ID/subscriptions/messages'
the value 'projects/$PROJECT_ID/subscriptions/messages' is taken as is and therefore the project ID contain uppercase and underscore, that violate the regex pattern.
Change for double quote and it should work great!
--parameters=inputSubscription="projects/$PROJECT_ID/subscriptions/messages"

How is my lambda function getting the match as an argument in my re.subn() expression?

I have a re.sub that searches for and increments a number. I searched the web for this solution. The solution works but I don't understand how the lambda function is obtaining its argument. As far as I know the re.subn() returns a tuple of the result string and the number of changes. It does not give you access to the matched string but somehow lambda is getting access to it.
resultstring, nmatches = re.subn(regex, lambda m: '{}{}'.format(m.group(1), int(m.group(2)) + 1), originalstring)
m is the string matched by regex and m.group(n) the captured groups.
Please inform me what is going on here.

Golang template engine pipelines

I have a Golang template, defined like this
{{- define "test" -}}
{{- printf "%s" .Name | trunc 24 -}}
{{- end -}}
Then I use it in one of my files:
{{ template "test" . }}
What does the dot mean after "test"? Golang template docs say:
{{template "name" pipeline}}
The template with the specified name is executed with dot set
to the value of the pipeline.
But I am not sure what pipeline is. Reading documentation gave no results, could anyone explain once again?
Also, why do we have to start values beginning with dot? E.g. {{ - printf "%s" .Name | trunc 24 -}}. Is it also a kind of pipeline?
Thank you in advance!
There are 2 template packages, text/template and html/template.
They have the same interface, but the html/template package is for generating HTML output safe against code injection, and should be used instead of text/template whenever the output is HTML.
Since they have the same interface but the html/template provides some extra functionality (contextual escaping of the inserted data), the basics and principles are only documented at text/html, and the documentation of html/template mostly focuses on detailing the extra.
That being said, "pipeline" belongs to the basics. It is documented in text/template, section Pipelines:
Pipelines
A pipeline is a possibly chained sequence of "commands". A command is a simple value (argument) or a function or method call, possibly with multiple arguments:
Argument
The result is the value of evaluating the argument.
.Method [Argument...]
The method can be alone or the last element of a chain but,
unlike methods in the middle of a chain, it can take arguments.
The result is the value of calling the method with the
arguments:
dot.Method(Argument1, etc.)
functionName [Argument...]
The result is the value of calling the function associated
with the name:
function(Argument1, etc.)
Functions and function names are described below.
A pipeline may be "chained" by separating a sequence of commands with pipeline characters '|'. In a chained pipeline, the result of each command is passed as the last argument of the following command. The output of the final command in the pipeline is the value of the pipeline.
"Arguments" and "pipelines" are evaluations of data.
The "dot" . is basically a cursor, pointing to somewhere in the data structure you pass when executing the template. The starting value of the dot is the value you pass, but this dot is modified by many actions, such as {{range}} or {{with}}.
Execution of the template walks the structure and sets the cursor, represented by a period '.' and called "dot", to the value at the current location in the structure as execution proceeds.
So when you write .Name, that means that the value where dot is pointing currently, you want to refer to its field or method or key called Name. For example if you pass a struct, at the beginning of your template .Name will denote the struct field Name if it exists, or its method named Name().
When you invoke / include another template, you have the possibility to tell what value you what to pass to its execution. When you write {{template "something" .}}, that means you want to pass the value currently pointed by dot to the template execution. If you want to pass only the Name field of the struct pointed by the dot, you may do it like {{template "something" .Name}}.
The value you pass as the pipeline in {{template}} will become the dot inside the invoked other template.
So as your template is being processed / rendered, the dot may be changed and point "only" to a part of the value originally passed to your template execution. Often it's handy or required to still reach the original value and not just the cursor. For this the template package provides the $:
When execution begins, $ is set to the data argument passed to Execute, that is, to the starting value of dot.
So even if you're inside a {{range}} for example (which sets the dot to the successive elements of the array / slice / map you're ranging over), you can still reach out and refer to any other parts of the value passed to the template execution.
So for example if you're ranging over a slice of books like {{range .Books}}, and if you need the Name field of the originally passed struct, you may do it inside {{range}} like this:
{{range .Books}}
Title: {{.Title}}
Original name: {{$.Name}}
{{end}}

String Trigger How to Create?

Hi I need to create a String trigger for the first time.
I need a trigger that check if the word deploy_succeeded from a script
The expression must trigger if anything else from deploy_succeeded appears happens, the strings could be any but after 8 minutes the trigger must alert.
I have create this one, but I am sure that is incorrect.
{NETGLOBE NODES FAIL SNMP V3:Netglobe_Nodes_Fail.sh[{HOST.DNS}].regexp("deploy_succeeded")}=1
Thanks.
Well, it is almost correct. It will alert if the string deploy_succeeded appears in the output. To reverse that you would change it to ...].regexp("deploy_succeeded")}=0.
Note that it will match a substring. If you want to match the exact string alone, use regexp("^deploy_succeeded$"). If you want to match substring, function str() might be a tiiiiny bit faster.
To check that deploy_succeeded has not been there for 8 minutes, use the count() function like this: count(8m,deploy_succeeded)=0.
Also see Zabbix trigger function documentation.

Facing difficulties with amazon url signature

I am following each step to create a signature for my url requests to amazon(or at least that's what I think) but it doesn't work.
I am trying to sign an example from the amazon's page( http://docs.aws.amazon.com/AWSECommerceService/latest/DG/rest-signature.html
I have downloaded the s3-sigtester, a javascript file that creates the signatures. The string that I am signing is:
GET \necs.amazonaws.co.uk \n/onca/xml \nAWSAccessKeyId=AKIAJOCH6NNDJFTB4LYA&Actor=Johnny%20Depp&AssociateTag=memagio-21&Operation=ItemSearch&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews%2CVariations&SearchIndex=DVD&Service=AWSECommerceService&Sort=salesrank&Timestamp=2014-10-19T21%3A21%3A55Z&Version=2009-01-01
The string above is the result from the sigtester. I am feeding it in hex. I get a signature and then, I am trying to access the following url, in order to get the xml values:
http://ecs.amazonaws.co.uk/onca/xml?AWSAccessKeyId=AKIAJOCH6NNDJFTB4LYA
&Actor=Johnny%20Depp&AssociateTag=memagio-21&Operation=ItemSe
arch&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews%2CV
ariations&SearchIndex=DVD&Service=AWSECommerceService&Signature=vZK%2BhDqtcV1CoTf6%2FN1ohR3Da5M%3D&Sort=salesrank&Ti
mestamp=2014-10-19T21%3A21%3A55Z&Version=2009-01-01
The AWASCcessKeyId and signature key are the AWS keys that I have created. However, I get an error that the signatures do not match. I think that I am following all the steps and I really don't know what's going on. Thanks.
The string that I am signing is:
GET \necs.amazonaws.co.uk \n/onca/xml \nAWSAccessKeyId=AKIAJOCH6NNDJFTB4LYA&Actor=Johnn
I assume \n denotes a newline character (Unicode 000A). The problem is that there should not be spaces before the newlines - it needs to be GET\necs.amazonaws.co.uk\n...