Amazon CloudWatch Insights Query - amazon-web-services

I have logs like this:
I, [2020-06-17T09:32:48.100103 #9] INFO -- : [54b35e04-9c19-443d-adff-b2c3192b5590] Completed 500 Internal Server Error in 7ms (ActiveRecord: 2.3ms | Allocations: 1705)
I, [2020-06-17T10:37:27.169909 #9] INFO -- : [c800e9ce-fba3-4e1a-a19f-526f32746925] Completed 401 Unauthorized in 0ms (ActiveRecord: 0.0ms | Allocations: 115)
So as you can see in message it is always fallowing the pattern: Completed [THE ERROR CODE] [ERROR MESSAGE] ...
I'm using this query to retrieve logs with certain error codes:
fields #timestamp, #message
| filter #message like /401/
| sort #timestamp desc
| limit 20
But how can I parse the message to get separate fields for error code and message?

You can use parse function with the regex syntax: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html
Like this for example:
parse #message /Completed (?<errorCode>\d+) (?<errorMessage>.+) in (?<timeMilis>\d+)ms /
| filter isPresent(errorCode)
Result will be something like this
-------------------------------------------------
| errorCode | errorMessage | timeMilis |
|-----------|-----------------------|-----------|
| 500 | Internal Server Error | 7 |
| 401 | Unauthorized | 0 |
-------------------------------------------------
This will just filter and extract the fields, you can do further processing from there.

Related

How to run a Cypress test several times in a row by modifying only one variable out of several?

I am creating my first cypress tests for the first time to test an endpoint.
This is the login.js
Given(
"Request to login in correct {string} with {string} and {string}, valid {string} and {string}",
(country, mail, password, token, udid) => {
cy.request({
method: "POST",
url: `${Cypress.env("BASE_URL")}/api/login`,
failOnStatusCode: false,
headers: {
Authorization: `Basic ${Cypress.env(cvp)}`,
"Content-Type": "application/json",
"MRKT": country,
},
body: {
email: Cypress.env(mail),
password: Cypress.env(password),
udid: Cypress.env(udid),
},
}).as("login");
}
);
Then("Status Code is {int}", (statusCode) => {
cy.get("#login").should((response) => {
expect(response.status).to.eq(statusCode);
});
});
and this is the login.feature
#login
Scenario Outline: login - Response 200
Given Request to login in correct '<country>' with '<mail>' and '<password>', valid '<token>' and '<udid>'
Then Status Code is 200
Examples:
| country | mail | password | token | udid |
| US | US_MAIL | PASSWORD | US_TOKEN | NO_UDID |
| UK | UK_MAIL | PASSWORD | UK_TOKEN | NO_UDID |
this is running perfectly, giving the desired result but now I'm stuck in a case where I want to pass the same user with different udid to test a device limitation error.
In this case I need to run 3 times the same data except the udid that must change in each of the executions to , after being 3 executions in a row , check that returns an error 429 (too many request).
Can I use the same js to test this case ?
An example of what I need to do is sometinhg like this:
#login
Scenario : login - Response 429 too many requests from
Given Request to login in correct US with US_EMAIL and MAIL, and PASSWORD valid TOKEN and provided FIRST_UDID
And Request to login in correct US with US_EMAIL and MAIL, and PASSWORD valid TOKEN and provided SECOND_UDID
And Request to login in correct US with US_EMAIL and MAIL, and PASSWORD valid TOKEN and provided THIRD_UDID
And Request to login in correct US with US_EMAIL and MAIL, and PASSWORD valid TOKEN and provided FOURTH_UDID
Then Status Code is 429
or
Scenario : login - Response 429 too many requests
Given Request login in correct '<country>' with '<mail>' and '<password>', valid '<token>' and provided '<udid>'
| country | mail | password | token | udid |
| US | US_MAIL | PASSWORD | TOKEN | FIRST_UDID |
And Request to login in correct '<country>' with '<mail>' and '<password>', valid '<token>' and provided '<udid>'
| country | mail | password | token | udid |
| US | US_MAIL | PASSWORD | TOKEN | SECOND_UDID |
And Request to login in correct '<country>' with '<mail>' and '<password>', valid '<token>' and provided '<udid>'
| country | mail | password | token | udid |
| US | US_MAIL | PASSWORD | TOKEN | THIRD_UDID |
And Request to login in correct '<country>' with '<mail>' and '<password>', valid '<token>' and provided '<udid>'
| country | mail | password | token | udid |
| US | US_MAIL | PASSWORD | TOKEN | FOURTH_UDID |
Then Status Code is 429
How can I run the same test 3 times in a row and check the error right after?
Each line in your Examples: should be considered a different independant test case. You should avoid linking cases using output from the previous Examples: line in the next Examples: line.
You should write a new Scenario Outline: for your 429 test since it has a different flow of actions.
#login
Scenario Outline: login - Response 200
Given Request to login in correct '<country>' with '<mail>' and '<password>', valid '<token>' and '<udid>'
Then Status Code is 200
Examples:
| country | mail | password | token | udid |
| US | US_MAIL | PASSWORD | US_TOKEN | NO_UDID |
| UK | UK_MAIL | PASSWORD | UK_TOKEN | NO_UDID |
Scenario Outline: login - Response 429 (Too many requests)
Given Request to login in correct '<country>' with '<mail>' and '<password>', valid '<token>' and '<udid1>'
And Request to login in correct '<country>' with '<mail>' and '<password>', valid '<token>' and '<udid2>'
And Request to login in correct '<country>' with '<mail>' and '<password>', valid '<token>' and '<udid3>'
Then Status Code is 429
Examples:
| country | mail | password | token | udid1 | udid2 | udid3 |
| US | US_MAIL | PASSWORD | US_TOKEN | NO_UDID | NO_UDID | NO_UDID |
| UK | UK_MAIL | PASSWORD | UK_TOKEN | NO_UDID | NO_UDID | NO_UDID |
I simply execute the same request as many times in a row as I need to, add the data directly and check the status after the number of requests needed.
I don't know if there is a better way to execute this case but it works perfectly.
Given Request to login in correct 'US' with 'US_MAIL' and 'PASSWORD', valid 'US_TOKEN' and 'FIRST_UDID'
Given Request to login in correct 'US' with 'US_MAIL' and 'PASSWORD', valid 'US_TOKEN' and 'SECOND_UDID'
Given Request to login in correct 'US' with 'US_MAIL' and 'PASSWORD', valid 'US_TOKEN' and 'THIRD_UDID'
Given Request to login in correct 'US' with 'US_MAIL' and 'PASSWORD', valid 'US_TOKEN' and 'FOURTH_UDID'
Then Status Code is 429

NoHttpResponseException on uploading file to S3 (camel-aws)

I am trying to upload around 10 GB file from my local machine to S3 (inside a camel route). Although file gets uploaded in around 3-4 minutes, but it also throwing following exception:
2014-06-26 13:53:33,417 | INFO | ads.com/outbound | FetchRoute | 167 - com.ut.ias - 2.0.3 | Download complete to local. Pushing file to S3
2014-06-26 13:54:19,465 | INFO | manager-worker-6 | AmazonHttpClient | 144 - org.apache.servicemix.bundles.aws-java-sdk - 1.5.1.1 | Unable to execute HTTP request: The target server failed to respond
org.apache.http.NoHttpResponseException: The target server failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:95)[142:org.apache.httpcomponents.httpclient:4.2.5]
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62)[142:org.apache.httpcomponents.httpclient:4.2.5]
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)[141:org.apache.httpcomponents.httpcore:4.2.4]
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)[141:org.apache.httpcomponents.httpcore:4.2.4]
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)[142:org.apache.httpcomponents.httpclient:4.2.5]
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)[142:org.apache.httpcomponents.httpclient:4.2.5]
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)[141:org.apache.httpcomponents.httpcore:4.2.4]
.......
at java.util.concurrent.FutureTask.run(FutureTask.java:262)[:1.7.0_55]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_55]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_55]
at java.lang.Thread.run(Thread.java:744)[:1.7.0_55]
2014-06-26 13:55:08,991 | INFO | ads.com/outbound | FetchRoute | 167 - com.ut.ias - 2.0.3 | Upload complete.
Due to which camel route doesn't stop and it is continuously throwing InterruptedException:
2014-06-26 13:55:11,182 | INFO | ads.com/outbound | SftpOperations | 110 - org.apache.camel.camel-ftp - 2.12.1 | JSCH -> Disconnecting from cxportal.integralads.com port 22
2014-06-26 13:55:11,183 | INFO | lads.com session | SftpOperations | 110 - org.apache.camel.camel-ftp - 2.12.1 | JSCH -> Caught an exception, leaving main loop due to Socket closed
2014-06-26 13:55:11,183 | WARN | lads.com session | eventadmin | 139 - org.apache.felix.eventadmin - 1.3.2 | EventAdmin: Exception: java.lang.InterruptedException
java.lang.InterruptedException
at EDU.oswego.cs.dl.util.concurrent.LinkedQueue.offer(Unknown Source)[139:org.apache.felix.eventadmin:1.3.2]
at EDU.oswego.cs.dl.util.concurrent.PooledExecutor.execute(Unknown Source)[139:org.apache.felix.eventadmin:1.3.2]
at org.apache.felix.eventadmin.impl.tasks.DefaultThreadPool.executeTask(DefaultThreadPool.java:101)[139:org.apache.felix.eventadmin:1.3.2]
at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks.execute(AsyncDeliverTasks.java:105)[139:org.apache.felix.eventadmin:1.3.2]
at org.apache.felix.eventadmin.impl.handler.EventAdminImpl.postEvent(EventAdminImpl.java:100)[139:org.apache.felix.eventadmin:1.3.2]
at org.apache.felix.eventadmin.impl.adapter.LogEventAdapter$1.logged(LogEventAdapter.java:281)[139:org.apache.felix.eventadmin:1.3.2]
at org.ops4j.pax.logging.service.internal.LogReaderServiceImpl.fire(LogReaderServiceImpl.java:134)[50:org.ops4j.pax.logging.pax-logging-service:1.7.1]
at org.ops4j.pax.logging.service.internal.LogReaderServiceImpl.fireEvent(LogReaderServiceImpl.java:126)[50:org.ops4j.pax.logging.pax-logging-service:1.7.1]
at org.ops4j.pax.logging.service.internal.PaxLoggingServiceImpl.handleEvents(PaxLoggingServiceImpl.java:180)[50:org.ops4j.pax.logging.pax-logging-service:1.7.1]
at org.ops4j.pax.logging.service.internal.PaxLoggerImpl.inform(PaxLoggerImpl.java:145)[50:org.ops4j.pax.logging.pax-logging-service:1.7.1]
at org.ops4j.pax.logging.internal.TrackingLogger.inform(TrackingLogger.java:86)[18:org.ops4j.pax.logging.pax-logging-api:1.7.1]
at org.ops4j.pax.logging.slf4j.Slf4jLogger.info(Slf4jLogger.java:476)[18:org.ops4j.pax.logging.pax-logging-api:1.7.1]
at org.apache.camel.component.file.remote.SftpOperations$JSchLogger.log(SftpOperations.java:359)[110:org.apache.camel.camel-ftp:2.12.1]
at com.jcraft.jsch.Session.run(Session.java:1621)[109:org.apache.servicemix.bundles.jsch:0.1.49.1]
at java.lang.Thread.run(Thread.java:744)[:1.7.0_55]
Please see my code below and let me know, where I am going wrong:
TransferManager tm = new TransferManager(
S3Client.getS3Client());
// TransferManager processes all transfers asynchronously,
// so this call will return immediately.
Upload upload = tm.upload(
Utils.getProperty(Constants.BUCKET),
getS3Key(file.getName()), file);
try {
upload.waitForCompletion();
logger.info("Upload complete.");
} catch (AmazonClientException amazonClientException) {
logger.warn("Unable to upload file, upload was aborted.");
amazonClientException.printStackTrace();
}
The stacktrace doesn't even have any reference to my code, hence couldn't determine where the issue is.
Any help or pointer would be really appreciated.
Thanks

Amazon Route 53 & Emails with Microsoft Outlook 365

I have setup my website with Amazon EC2 and Route53 successfully. Our company decided to go with Microsoft Exchange for their email.
Microsoft online told me to add a TXT and MX record in the DNS registry. Works great! Can now send emails. However when people sometimes email me from a Google account (known, there could be other servies I don't know about) They receive an error like this:
This is an automatically generated Delivery Status Notification
THIS IS A WARNING MESSAGE ONLY.
YOU DO NOT NEED TO RESEND YOUR MESSAGE.
Delivery to the following recipient has been delayed:
[[EMAIL_ADDRESS]]
Message will be retried for 1 more day(s)
Technical details of temporary failure:
DNS Error: Domain name not found
Do you know how I can fix this. My web address is visible and working and some people can send me emails fine but others get this.
UPDATE: DNS RECORDS
+----------------------+-----+---------------------------------------------------------------------------------------------+--------+
| charterbox.com.au. | A | 54.252.90.224 | 3600 |
| charterbox.com.au. | MX | 0 ms36130019.msv1.invalid.outlook.com | 3600 |
| charterbox.com.au. | NS | ns-1099.awsdns-09.org. ns-138.awsdns-17.com. ns-830.awsdns-39.net. ns-1960.awsdns-53.co.uk. | 172800 |
| charterbox.com.au. | SOA | ns-1099.awsdns-09.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400 | 900 |
| charterbox.com.au. | TXT | "MS=ms36130019" | 3600 |
| *.charterbox.com.au. | A | 54.252.90.224 | 300 |
+----------------------+-----+---------------------------------------------------------------------------------------------+--------+
The MX record you have in place looks like the record used to verify your domain. You will need to change it to the production mx records. You can find the specific value(s) for your domain in the domain administration section of the admin page at portal.microsoftonline.com. Once you update the MX records, you should be good to go.

What are the potential status codes for AWS Auto Scaling Activities?

Here is the documentation for the Activity data type.
However, I think I've seen 4 status codes for the responses:
'Successful'
'Cancelled'
'InProgress'
'PreInProgress'
Are there any others?
Looks like they have updated the documentation, in the same url you have shared:
Valid Values: WaitingForSpotInstanceRequestId | WaitingForSpotInstanceId | WaitingForInstanceId | PreInService | InProgress | Successful | Failed | Cancelled

Exception in invoking web Services with grails

I am trying to use a external web service in my grails project following http://grails.org/Calling+External+WebServices
my wsdl - https://devora11.gryphon.priv/axis2/services/GDXAppWS?wsdl
Here's a simple code in controller where i am trying to use groovyx.net.ws.WSClient-:
def proxy = new WSClient("https://devora11/axis2/services/GDXAppWS?wsdl", this.class.classLoader)
println "Proxy bfr "+proxy ;
//proxy.setSSLProperties(['port',':443'])
//println "Proxy "+proxy ;
print proxy.isSpecifiedSQLAlive()
but it throws error all the time-
java.lang.NullPointerException
at groovyx.net.ws.AbstractCXFWSClient.invokeMethod(AbstractCXFWSClient.java:87)
at com.ggw.LoadController$_closure2$$ENKIcufD.doCall(LoadController.groovy:41)
at org.grails.plugin.resource.DevModeSanityFilter.doFilter(DevModeSanityFilter.groovy:26)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
On STS IDE shows
ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] MyProj/load/wsTest
Stacktrace follows:
Message: null
Line | Method
->> 87 | invokeMethod in groovyx.net.ws.AbstractCXFWSClient
| 41 | doCall in com.ggw.LoadController$_closure2$$ENKIcufD
| 26 | doFilter . . in org.grails.plugin.resource.DevModeSanityFilter
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . . . in ''
^ 662 | run in java.lang.Thread
Looks like you have the URL for your web service wrong.