I am creating a step function and there is a condition like this
if my step output is "is_query" : True then I have to move a different step and if false then I have to go to diffrent step I am following this example https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_stepfunctions/README.html
I got idea from this like this :
for example If I do something like this :
sfn_step_1.next(sfn_step_2).next(sfn.Choice(self, "Job Complete?").when(sfn.Condition.string_equals("$.is_query", "True"), sfn_special_step ).when(sfn.Condition.string_equals("$.is_query", "False"), Do Nothing ).next(sfn_step_3)
So I have 2 questions how I can make this Do Nothing and move to step 3 as at the end I want both to go to step 3 . just a extra step in is_query to True case. And 2nd question how I can add "is_query", "True" to payload for now my step 2 payload look like this :
sfn_step_2 = tasks.LambdaInvoke(self, "check-status",
lambda_function=check_status_lambda,
output_path="$.Payload",
integration_pattern=stepfunctions.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
payload=stepfunctions.TaskInput.from_object({
"payload.$": "$",
"execution_id.$": "$$.Execution.Id",
"taskToken": stepfunctions.JsonPath.task_token
})
)
Instead of the second condition just add
.afterwards()).next(your next step)
this will solve both problems.
on your code is like this:
sfn_step_1.next(sfn_step_2).next(sfn.Choice(self, "Job Complete?").when(sfn.Condition.string_equals("$.is_query", "True"), sfn_special_step ).afterwards()).next(sfn_step_3)
Related
Currently I have a yaml file which includes different states in the Step function that runs different checks and returns pass or fail output
code Snippet:
Comment: Check all steps
StartAt: Check A
States:
Check A:
Comment: Verifies that A is done
Resource: "arn:aws:lambda:us-east-1:123456789012:function:checkA",
Next: Check B
Check B:
Comment:Verifies that B is done
Resource: "arn:aws:lambda:us-east-1:123456789012:function:checkB"
Next: Check C
Check C:
Comment:Verifies that C is done
Resource: "arn:aws:lambda:us-east-1:123456789012:function:checkC"
ResultPath: "$.ValidatedResults"
End: true
How can I modify this step function to accept an input map such that it only executes those States with boolean true
"OnlyVerify": {
"Check A": true,
"Check B": false
"Check C": true
}
And if OnlyVerify map is not specified as input to the Step function, it should run all the Checks.(True for all checks by default)
Expected Output
{
"OnlyVerify": {
"Check A": true,
"Check B": false
"Check C": true
},
"ValidatedResults": {
"Check A": PASS,
"Check C": PASS
}
}
Appreciate any guidance here
I would suggest playing with the logic a bit in the Workflow Studio, but something like this should get you most of the way there:
If the lambda function used to do the checking can be refactored to handle any of [A, B, C, ...] then that would enable making the step function definition much "cleaner" by leveraging a Map State, rather than a parallel state.
I have a 3 step state machine for a step function.
InputStep -> ExecuteSparkJob -> OutputLambda
ExecuteSparkJob is a glue task. Since it cannot pass its output to the step function, it writes it output to an S3 bucket. OutputLambda reads it from there and passes it on to the step function.
The idea of InputStep is simply to define a common S3 URI that the following steps can use.
Below is the code I have for the Input Step.
const op1 = Data.stringAt("$.op1");
const op2 = Data.stringAt("$.op2");
const inputTask = new Pass(this, "Input Step", {
result: Result.fromString(this.getURI(op1, op2)),
resultPath: "$.s3path"
});
getURI(op1: string, op2: string): string {
return op1.concat("/").concat(op2).concat("/").concat("response");
}
However, the string manipulation that I am doing in getURI is not working. The values in inputTask.result are not being substituted by the value in Path.
This is the input and output to the Input Step
{
"op1": "test1",
"op2": "test2"
}
Output
{
"op1": "test1",
"op2": "test2"
"responsePath": "$.op1/$.op2/response"
}
Is it possible to do some string manipulations using parameters in the Path in Step Function definition? If yes, what am I missing?
Thanks for your help.
You can use one or more EvaluateExpression Tasks - it's still a bit clunky.
You can find examples here.
API doc here.
Use a Lambda function instead of a Pass state to build the string.
Step Functions doesn't currently support string concatenation with reference paths. The Result field of a Pass state doesn't allow reference paths either. It has to be static value.
The Pass state's Parameters field supports the intrinsic functions and substitutions you need to do this natively, without a Lambda task. The Result field doesn't.
Compose a string from the execution inputs with the Format intrinsic function:
const inputTask = new Pass(this, "Input Step", {
parameters: {
path: JsonPath.format(
"{}/{}/response",
JsonPath.stringAt("$.op1"),
JsonPath.stringAt("$.op2")
),
},
outputPath: "$.s3",
});
The resulting string value test1/test2/response will be output to $.s3.path.
I am trying to build a module that will apply only in conditions when the requirements of the statement are satisfied. In this case if I specify the value for "var.enable_standbyinfra" that is true then the module will be created. I want to understand if I am approaching this type of method wrong or get on the right path
iam_instance_profile_standby = "${var.enable_standbyinfra == "true" ?
module.aem_disp_a_standby_iam.aws_iam_instance_profile_id : 0 }"
and further used in:
iam_instance_profile = "${local.iam_instance_profile_standby}"
The result is that I get an error when running terraform and the error is:
local.iam_instance_profile_standby: At column 3, line 1: true and false expression types must match; have type list and type int in:
${var.enable_standbyinfra == "true" ? module.aem_disp_a_standby_iam.aws_iam_instance_profile_id : 0 }
So the final result I want to get to is that if I specify that "var.enable_standbyinfra" is equal to true the resource is created. If set to "false" I want it to be skipped.
If I posted it wrong without a clear understanding please accept my excuses I am not a expert user in stackoverflow still learning
This argument should be a string, so:
var.enable_standbyinfra == "true" ?
module.aem_disp_a_standby_iam.aws_iam_instance_profile_id : ""
After working with loopback for the past 6 months, i have now encountered a problem i can't seem to figure out the reason for.
My problem occurs when using loopbacks, "where" with a "and" condition.
Like.find({
"where: {
"and": [{
"relation_id": ctx.instance.relation_id
},
{
"user_id": ctx.options.accessToken.userId
}
]
}
})
Above is the call with the where/and filter included.
I console.log the values before the call and see:
"ctx.instance.relation_id" which prints "59a32764029ab660b1c7f862"
"ctx.options.accessToken.userId" which prints "59a32597c606a85b5e08db18"
And below is the object i am trying to query:
{
"_id" : ObjectId("59a5cade884d8c48e135768c"),
"user_id" : "59a32597c606a85b5e08db18",
"relation_id" : "59a32764029ab660b1c7f862",
"created_at" : ISODate("2017-08-29T22:13:18.209+02:00"),
"status" : NumberInt("1")
}
Now. Calling the find() function without the "and" condition for just one of the values, either user_id or relation_id, returns the expected result, but with the "and" it returns an empty array.
The official Loopback documentation gives this examples for using the where/and filter:
Post.find({where: {and: [{title: 'My Post'}, {content: 'Hello'}]}},
function (err, posts) {
...
});
as shown here
And as far as i can tell, my query matches it completely, but still don't get the expected results. I know that there could be many reasons why it fails, but i was hoping someone here, maybe could give some pointers or provide insight i could use to solve my issue.
Thanks
I'm making my first steps in the Jenkins workflow (Jenkins ver 1.609.1)
I need to read a file, line by line, and then run regex on each line.
I'm interested in the regex "grouping" type, however "project" and "status" variables (the code below) get null value in Jenkins . Any suggestions what is wrong and how to fix it ?
def line = readFile (file)
def resultList = line.tokenize()
for(item in resultList ){
(item =~ /(\w+)=(\w+)$/).each { whole, project, status ->
println (whole)
println (project)
println (status)
}
}
each with a closure will not work: JENKINS-26481
If something using advanced language features works in standalone Groovy but not in Workflow, try just encapsulating it in a method marked #NonCPS. This will effectively run it as a “native” method. Only do this for code you are sure will run quickly and not block on I/O, since it will not be able to survive a Jenkins restart.
Well,
After checking out some other regex options I came around with the following solution that seems working :
def matcher = item =~ /(?<proj>\w+)=(?<status>\w+)/
if( matcher.matches() ) { etc...}