How i can list all log in a group in lambdafunction aws - aws-lambda

I try with #aws-sdk.
I don't know what is function support to list logs.

Create and run StartQueryCommand: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-cloudwatch-logs/classes/startquerycommand.html
Get queryId from above
Create and run GetQueryResultsCommand with queryId finded:
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-cloudwatch-logs/classes/getqueryresultscommand.html
Result of step 3 have status. if status equal 'running' run again step 3 until status equal 'Complete'.

Related

Ansible playbook to compare 2 register output

I have created 2 tasks to fetch the 2 below outputs:
first output:
NAME STATUS ROLES AGE VERSION
control1.eee-dev.dd.k8s.c0.ms.com Ready master 146d v1.18
control2.eee-dev.dd.k8s.c0.ms.com Ready master 146d v1.18
control3.eee-dev.dd.k8s.c0.ms.com Ready master 146d v1.18
dd900xc15xx.nodes.c0.ms.com Ready worker 146d v1.18
dd900xc16xx.nodes.c0.ms.com Ready worker 146d v1.18
second output:
Transaction ID: xxxx-xxxx-xxxxx-xxxxxx
bootstrap.eee-dev.dd.k8s.c0.ms.com
control1.eee-dev.dd.k8s.c0.ms.com
control2.eee-dev.dd.k8s.c0.ms.com
control3.eee-dev.dd.k8s.c0.ms.com
dd900xc15xx.nodes.c0.ms.com
dd900xc16xx.nodes.c0.ms.com
Now, how do I compare the above 2 outputs stored in register and print PASSED, if NAME(from first output, meaning only the nodes from the first column) matches with the second output? if not FAILED. Note: we need to ignore the first 2 lines from the second output
I'm thinking to do it by logic(filter the node names and do comparison), but unsure about how do I convert this into an ansible playbook. Highly appreciate your suggestions and comments to achieve this.

ISDeploymentWizard.exe command (SSIS deployment ) in CMD doesn't print any indication for status

I'm running the below command in CMD for SSIS:
ISDeploymentWizard.exe /Silent /ModelType:Project /SourcePath:"C:\TEST\Integration Services.ispac" /DestinationServer:"TEST03,1111" /DestinationPath:"/TEST/DEVOPS"
and it finished successfully but with no indication to the command line. I can only check with SSMS to make sure it was really deployed. any idea why?
Solid observation here #areilma - the /silent option eliminates all status info. I had always assumed that flag controlled whether the gui was displayed or not.
If I run this command
isdeploymentwizard.exe /Silent /ModelType:Project /SourcePath:".\SO_66497856.ispac" /DestinationServer:".\dev2017" /DestinationPath:"/SSISDB/BatchSizeTester/SO_66497856"
My package is deployed to my local machine at the path specified. Removing the /silent option causes the GUI to open up with the prepopulated values.
isdeploymentwizard.exe /ModelType:Project /SourcePath:".\SO_66497856.ispac" /DestinationServer:".\dev2017" /DestinationPath:"/SSISDB/BatchSizeTester/SO_66497856"
When the former command runs, nothing is printed to the command prompt. So that's happy path deployment, maybe if something is "wrong", I'd get an error message on the command line. And this is where things got "interesting".
I altered my destination path to a folder that doesn't exist. I know the tool doesn't create a path if it doesn't exist and when I ran it, I didn't get an error back on the command line. What I did get, was a pop up windowed error of
TITLE: SQL Server Integration Services
The path does not exist. The folder 'cBatchSizeTester' was not found in catalog 'SSISDB'. (Microsoft.SqlServer.IntegrationServices.Wizard.Common)
BUTTONS:
OK
So the /silent option removes the gui to allow us to have an automated deploy but if a bad value is passed, we return to having a gui... I then repeated with a bad server name, which led to a second observation. The second I hit enter, the command line returned ready for the next command. 15 seconds later however,
TITLE: SQL Server Integration Services
Failed to connect to server .\dev2017a. (Microsoft.SqlServer.ConnectionInfo)
ADDITIONAL INFORMATION:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=-1&LinkId=20476
Well now, that tells me that the actual deployment is an independent spawned process. So it won't return any data back to the command line, in any case.
Since I assume we're looking at this from a CI/CD perspective, what can we do? We could fire off a sqlcmd afterwards looking for an entry in the SSISDB catalog views to see what happened. Something like this
SELECT TOP 1 O.end_time, SV.StatusValue, F.name AS FolderName, P.name AS ProjectName FROM catalog.operations AS O
CROSS APPLY
(
SELECT
CASE O.status
WHEN 1 THEN 'Created'
WHEN 2 THEN 'Running'
WHEN 3 THEN 'Canceled'
WHEN 4 THEN 'Failed'
WHEN 5 THEN 'Pending'
WHEN 6 THEN 'Ended unexpectedly'
WHEN 7 THEN 'Succeeded'
WHEN 8 THEN 'Stopping'
WHEN 9 THEN 'Completed'
END AS StatusValue
)SV
INNER JOIN catalog.object_versions AS OV ON OV.object_id = O.object_id
INNER JOIN catalog.projects AS P ON P.object_version_lsn = OV.object_version_lsn
INNER JOIN catalog.folders AS F ON F.folder_id = P.folder_id
/*
INNER JOIN
catalog.packages AS PKG
ON PKG.project_id = P.project_id
*/
WHERE O.operation_type = 101 /*deploy project*/
AND P.name = 'SO_66497856' /*project name*/
AND F.name = 'BatchSizeTester'
ORDER BY o.created_time DESC
Perhaps a filter against end_time of within the past 10 seconds would be appropriate and if we have a result and the status is Succeeded we got a deploy. No result means it failed. I presume something similar happens when the gui runs and despite all this testing, I'm not interested in firing up a trace to fully round out this answer and see what happens behind the scenes.
If you want to negate the value of the prebuilt tool, the other option would be to use the ManagedObjectModel/PowerShell approach to deploy as you can get info from there. The other deployment option is with the TSQL Commands. The second link in my documentation section outlines what that would look like
Paltry documentation I could find
I could find no documentation as to the command line switches for isdeploymentwizard.exe
Deploy an SSIS project from the command prompt with ISDeploymentWizard.exe
Deploy Integration Services (SSIS) Projects and Packages
From #arielma's deleted answer, they found a more succinct answer saying "not possible"

Shell Scripting to compare the value of current iteration with that of the previous iteration

I have an infinite loop which uses aws cli to get the microservice names, it's parameters like desired tasks,number of running task etc for an environment.
There are 100's of microservices running in an environment. I have a requirement to compare the value of aws ecs metric running task for a particular microservice in the current loop and with that of the previous loop.
Say name a microservice X has the metric running task 5. As it is an infinite loop, after some time, again the loop come for the microservice X. Now, let's assume the value of running task is 4. I want to compare the running task for currnet loop, which is 4 with the value of the running task for the previous run, which is 5.
If you are asking a generic question of how to keep a previous value around so it can be compared to the current value, just store it in a variable. You can use the following as a starting point:
#!/bin/bash
previousValue=0
while read v; do
echo "Previous value=${previousValue}; Current value=${v}"
previousValue=${v}
done
exit 0
If the above script is called testval.sh. And you have an input file called test.in with the following values:
2
1
4
6
3
0
5
Then running
./testval.sh <test.in
will generate the following output:
Previous value=0; Current value=2
Previous value=2; Current value=1
Previous value=1; Current value=4
Previous value=4; Current value=6
Previous value=6; Current value=3
Previous value=3; Current value=0
Previous value=0; Current value=5
If the skeleton script works for you, feel free to modify it for however you need to do comparisons.
Hope this helps.
I dont know how your input looks exactly, but something like this might be useful for you :
The script
#!/bin/bash
declare -A app_stats
while read app tasks
do
if [[ ${app_stats[$app]} -ne $tasks && ! -z ${app_stats[$app]} ]]
then
echo "Number of tasks for $app has changed from ${app_stats[$app]} to $tasks"
app_stats[$app]=$tasks
else
app_stats[$app]=$tasks
fi
done <<< "$( cat input.txt)"
The input
App1 2
App2 5
App3 6
App1 6
The output
Number of tasks for App1 has changed from 2 to 6
Regards!

While running the "pmrep massupdate" command, I see an error "workflow object workflow_name cannot be fetched. Any idea how to resolve it?

Command used:
{
pmrep massupdate -i modify_session -t 'session_config_property' -n 'Stop on errors' -v 1 -u output.log_modify
}
Snippet from output.log_modify
workflow object wf_DS_DW_SampleDim cannot be fetched.
Massupdate Summary:
Number of reusable sessions that are successfully updated: 0.
Number of non-reusable sessions that are successfully updated: 0.
Number of session instances that are successfully updated: 0.
Number of reusable sessions that fail to be updated: 0.
Number of non-reusable sessions that fail to be updated: 1.
Number of session instances that fail to be updated: 0.
Not sure why it fails for certain workflows and works for others. Any idea?

How to ignore error and continue with rest of the script

Some background. I want to delete AWS Redshift cluster and the process takes more than 30 minute. So this is what I want to do:
Start the deletion
Every 1 minute, check the cluster status (it should be “deleting”)
When the cluster is deleted, the command would fail (because it
cannot find the cluster anymore). So log some message and continue with rest of the script
This is the command I run in a while loop to check the cluster status after I start the deletion:
resp = redshift.client.describe_clusters(:cluster_identifier=>"blahblahblah")
Above command will get me cluster status as deleting while the deletion process continues. But once the cluster is completely deleted, then the command itself will fail as it cannot find the cluster blahblahblah.
Here is the error from command once the cluster is deleted:
/var/lib/gems/1.9.1/gems/aws-sdk-1.14.1/lib/aws/core/client.rb:366:in `return_or_raise': Cluster blahblahblah not found. (AWS::Redshift::Errors::ClusterNotFound)
I agree with this error. But this makes my script exit abruptly. So I want to log a message saying The cluster is deleted....continuing and continue with my script.
I tried below settings
resp = redshift.client.describe_clusters(:cluster_identifier=>"blahblahblah")
|| raise (“The cluster is deleted....continuing”)
I also tried couple of suggestion mentioned at https://www.ruby-forum.com/topic/133876
But this is not working. My script exits once above command fails to find the cluster.
Questions:
How to ignore the error, print my own message saying “The cluster is deleted....continuing” and continue with the script ?
Thanks.
def delete_clusters clusters=[]
cluster.each do |target_cluster|
puts "will delete #{target_clust}"
begin
while (some_condition) do
resp = redshift.client.describe_clusters(:cluster_identifier => target_clust)
# break condition
end
rescue AWS::Redshift::Errors::ClusterNotFound => cluster_exception
raise ("The cluster, #{target_clust} (#{cluster_excption.id}), is deleted....continuing")
end
puts "doing other things now"
# ....
end
end
#NewAlexandria, I changed your code to look like below:
puts "Checking the cluster status"
begin
resp = redshift.client.describe_clusters(:cluster_identifier=>"blahblahblah")
rescue AWS::Redshift::Errors::ClusterNotFound => cluster_exception
puts "The cluster is deleted....continuing"
end
puts "seems like the cluster is deleted and does not exist"
OUTPUT:
Checking the cluster status
The cluster is deleted....continuing
seems like the cluster is deleted and does not exist
I changed the raise to puts in the line that immediately follows the rescue line in your response. This way I got rid of the RuntimeError that I mentioned in my comment above.
I do not know what are the implication of this. I do not even know whether this is the right way to do it. But It shows the error when the cluster is not found and then continues with the script.
Later I read a lot of articles on ruby exception/rescue/raise/throw.... but that was just too much for me to understand as I do not belong to programming background at all. So, if you could explain what is going on here, it will really helpful for me to get more confidence in ruby.
Thanks for your time.

Resources