AWS Lambda Java Function is successful but times out - java

I created a basic AWS Lambda java function to convert an xml message to json. The function is triggered off of an S3 event (message is converted and dropped in different S3 bucket). It appears to be successful, I can see the steps in cloudwatch and the converted message is in the S3 destination bucket. However, I see the timeout warning in the cloud watch logs (set timeout to 15 seconds). I must be missing something, definitely a newby when it comes to Lambda. Do I need to provide the context with a done or success? Any suggestions or tips would be greatly appreciated.
Code Snippet:
public void msgConvertToJson(S3Event s3event, Context context) {
final String key = s3event.getRecords().get(0).getS3().getObject().getKey();
final String bucketName = s3event.getRecords().get(0).getS3().getBucket().getName();
log.info("key: " + key + " bucketName:" + bucketName);
String action = "";
try {
//Attempt to retrieve the message from S3 on notification
log.info("attempting to get message");
action = "get";
final String message = s3Client.getObjectAsString(bucketName, key);
//Attempt to parse and convert the message to JSON
log.info("attempting to parse message");
String msgJson = new MessageParser(message).getMessageJson();
//Attempt to write the converted message to a new S3 bucket
final String parsedBucket = "parsed-" + bucketName;
final String newKey = key.replace(".xml",".json");
log.info("newKey: " + newKey + " parsedBucketName:" + parsedBucket);
log.info("attempting to put message");
action = "put";
s3Client.putObject(parsedBucket, newKey, msgJson );
} catch (AmazonServiceException ase) {
log.error("Caught an AmazonServiceException trying to " + action + " file " + key + ", which " +
"means your request made it " +
"to Amazon S3, but was rejected with an error response" +
" for some reason.");
log.error("Error Message: " + ase.getMessage());
log.error("HTTP Status Code: " + ase.getStatusCode());
log.error("AWS Error Code: " + ase.getErrorCode());
log.error("Error Type: " + ase.getErrorType());
log.error("Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
log.error("Caught an AmazonClientException while trying to " + action + " file " + key + ", which " +
"means the client encountered " +
"an internal error while trying to " +
"communicate with S3, " +
"such as not being able to access the network.");
log.error("Error Message: " + ace.getMessage());
}
}

It actually turned out that it was just the timeout was too short. The cold start for the JVM, must be taking longer than I would have thought. I was just assuming I had another issue in my code. Bumped memory to 192 and timeout to 45 seconds. Hope this helps someone else.
Really unfortunate I was marked down by someone that was pointing me at the wrong information (NodeJS) instead of Java.

Related

How to set Multiple Option of Payment In PayUMoney Payment Gateway in Android

my dependency file here
implementation 'com.payumoney.sdkui:plug-n-play:1.6.1'
payUmoney code
private fun startPay() {
builder.setAmount(amount) // Payment amount
.setTxnId(txnid) // Transaction ID
.setPhone(phone) // User Phone number
.setProductName(prodname) // Product Name or description
.setFirstName(firstname) // User First name
.setEmail(email) // User Email ID
.setsUrl("https://www.payumoney.com/mobileapp/payumoney/success.php") // Success URL (surl)
.setfUrl("https://www.payumoney.com/mobileapp/payumoney/failure.php") //Failure URL (furl)
.setUdf1("")
.setUdf2("")
.setUdf3("")
.setUdf4("")
.setUdf5("")
.setUdf6("")
.setUdf7("")
.setUdf8("")
.setUdf9("")
.setUdf10("")
.setIsDebug(true) // Integration environment - true (Debug)/ false(Production)
.setKey(pro_merchantkey) // Merchant key
.setMerchantId(pro_merchantId);
try {
paymentParam = builder.build()
getHashkey()
} catch (e: Exception) {
Log.d("afkafbakabkab", " errors $e")
}
}
payment flow stating from here
private fun getHashkey() {
paymentParam!!.setMerchantHash(CreateHash())
PayUmoneyFlowManager.startPayUMoneyFlow(paymentParam, this as PaymentGateways, R.style.AppTheme_default, true);
}
generating hash key from this code
private fun CreateHash(): String {
var hashSequence: String = pro_merchantkey + "|" + txnid + "|" + amount + "|" + prodname + "|" + firstname + "|" + email + "|" +
udf1 + "|" + udf2 + "|" + udf3 + "|" + udf4 + "|" + udf5 +"||||||"+ pro_salt;
val hash = hashcal("SHA-512", hashSequence)
return hash
}
note :- i am getting only one payment option i want to get multiple payment options like netbanking ,Upi
you have set setIsDebug() true; for some resaons PayU have only provided test cards for testing purposes.
So, the release build will have all the options.
in simple words set setIsDebug(false) and you will get all the options.

Consecutive log prints - only the first printed (no visible error)

I have this code fragment in my java class:
catch (AuthenticationFailedException afe) {
IlientConf.logger.error("[" + accountID + "," + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer() + "] " + "E-Mail " + protocol + encStr + " login failed on " + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer());
IlientConf.logger.error("[" + accountID + "," + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer() + "] " + afe.getMessage());
IlientConf.logger.debug("Email integration AuthenticationFailedException", afe);
return false;
}
IlientConf.logger is a log4j logger.
The actual log that is printed contains only the first line. This is it:
[someuser,sapunlock#someuser.com#outlook.office365.com] E-Mail pop3
(SSL) login failed on sapunlock#someuser.com#outlook.office365.com
The second and the third log statements are lost somehow.
I really need the stack trace of the error, but I can't get it.
No other related error is shown in the log.
Please help me understand what the reason for this is.
P.S.: Of course I can change the log statements to show this better, but this is deployed at a customers environment and needs to be solved before the next version.

What is the syntax of Firebase notification

I want to write the firebase notification as a String like JSON format .. I already sent the notification for one device but when trying to send to multiple devices i got bad request ..
params = new StringEntity("{\n" +
" \"to\" : \"ds1YTh...UUZOos\",\n" +
" \"notification\" : {\n" +
" \"body\" : \""+jobTitle+"\",\n" +
" \"title\" : \"New Job!\",\n" +
" \"icon\" : \"hire\"\n" +
" \"sound\" : \"default\"\n"+
" \"time_to_live\" : "+3600+
" }\n" +
" \"data\": {"+
" }"+
" }");
how could i do that .. and if I can't do it this way what is the best way to implement this .. I'm using HttpClient and HttpPost and primefaces 5.3
First a few relevant links:
Sending notifications to multiple devices not subscribed to a certain topic
the Firebase documentation on sending downstream messages
the Firebase documentation on sending to multiple devices (which covers using topics and device groups)
FCM (Firebase Cloud Messaging) Send to multiple devices
But if you want to stick closest to your current code, you should be able to specify the device tokens in a registration_ids property:
params = new StringEntity("{\n" +
" \"registration_ids\" : [\"ds1YTh...UUZOos\", \"et2ZUi...VVUPpt\"],\n" +
" \"notification\" : {\n" +
" \"body\" : \""+jobTitle+"\",\n" +
" \"title\" : \"New Job!\",\n" +
" \"icon\" : \"hire\"\n" +
" \"sound\" : \"default\"\n"+
" \"time_to_live\" : "+3600+
" }\n" +
" \"data\": {"+
" }"+
" }");
I have done it in Asp.net I hope it will help in some way...
for (int i = 0; i < dt.Rows.Count (No. of Rows or Device); i++)
{
tRequest.ContentType = "application/json";
var data1 = new
{
to="" + DeviceID + "",
priority="high",
notification = new
{
body = Message,
is_background = true,
title = Heading,
appicon = "http://webbestsites.com/images/1_icon.png",
sound = "default"
},
}

How to set the multiple attributes of objectClass for UnboundID & OpenLDAP via Java 7

I'm not sure how to properly pass the multiple attributes needed for an OpenLDAP insert via UnboundID. I have omitted the objectClass attributes & received a "no objectClass" error. I have also tried comma-separated & the bracket/array route like below & received the "value #0 invalid per syntax" error.
String[] ldifLines = {"dn: ou=users,dc=sub,dc=domain,dc=com", "cn: " + uid, "userPassword: " + pw, "description: user", "uidNumber: " + lclDT, "gidNumber: 504", "uid: " + uid, "homeDirectory: " + File.separator + "home" + File.separator + this.getStrippedUser(), "objectClass: {posixAccount, top}"};
LDAPResult ldapResult = lclLC.add(new AddRequest(ldifLines));
So, the question is, how do I successfully pass these objectClass attributes in the string array included above? Again, I have tried: "objectClass: top, posixAccount" as well. Thanks in advance!
It uses an LDIF representation, so if an attribute has multiple values, then the attribute appears multiple times. Like:
String[] ldifLines =
{
"dn: ou=users,dc=sub,dc=domain,dc=com",
"objectClass: top",
"objectClass: posixAccount"
"cn: " + uid,
"userPassword: " + pw,
"description: user",
"uidNumber: " + lclDT,
"gidNumber: 504",
"uid: " + uid,
"homeDirectory: " + File.separator + "home" +
File.separator + this.getStrippedUser(),
};
LDAPResult ldapResult = lclLC.add(new AddRequest(ldifLines));
Also, the LDAP SDK allows you to use a shortcut and just do it in a single call without the need to create the array or the AddRequest object, like:
LDAPResult ldapResult = lclLC.add(
"dn: ou=users,dc=sub,dc=domain,dc=com",
"objectClass: top",
"objectClass: posixAccount"
"cn: " + uid,
"userPassword: " + pw,
"description: user",
"uidNumber: " + lclDT,
"gidNumber: 504",
"uid: " + uid,
"homeDirectory: " + File.separator + "home" +
File.separator + this.getStrippedUser());

Java vs. Net HTTP Client Performance

We call a webservice from our C# app which takes about 300ms using WCF (BasicHttpBinding). We noticed that the same SOAP call does only take about 30ms when sending it from SOAP UI.
Now we also implemented a test accessing the webservice via a basic WebClient in order to make sure that the DeSer-part of the WCf is not the reason for this additional delay. When using the WebClient class the call takes about 300ms as well.
Any ideas on why Java compared to C# is about 10x faster in this regard? Is there some kind of tweaking possible on the .NET side of things?
private void Button_Click(object sender, RoutedEventArgs e)
{
executeTest(() =>
{
var resultObj = client.getNextSeqNr(new WcfClient()
{
domain = "?",
hostname = "?",
ipaddress = "?",
loginVersion = "?",
processId = "?",
program = "?",
userId = "?",
userIdPw = "?",
userName = "?"
}, "?", "?");
});
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
WebClient webClient = new WebClient();
executeTest(()=>
{
webClient.Proxy = null;
webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
webClient.Headers.Add("Content-Type", "application/xml");
webClient.Encoding = Encoding.UTF8;
var data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"SomeNamespace\">" +
" <soapenv:Header/>" +
" <soapenv:Body>" +
" <ser:getNextSeqNr>" +
" <!--Optional:-->" +
" <clientInfo>" +
" <!--Optional:-->" +
" <domain>?</domain>" +
" <!--Optional:-->" +
" <hostname>?</hostname>" +
" <!--Optional:-->" +
" <ipaddress>?</ipaddress>" +
" <!--Optional:-->" +
" <loginVersion>?</loginVersion>" +
" <!--Optional:-->" +
" <processId>?</processId>" +
" <!--Optional:-->" +
" <program>?</program>" +
" <!--Optional:-->" +
" <userId>*</userId>" +
" <!--Optional:-->" +
" <userIdPw>?</userIdPw>" +
" <!--Optional:-->" +
" <userName>?</userName>" +
" </clientInfo>" +
" <!--Optional:-->" +
" <name>?</name>" +
" <!--Optional:-->" +
" <schema>?</schema>" +
" </ser:getNextSeqNr>" +
" </soapenv:Body>" +
"</soapenv:Envelope>";
string result = webClient.UploadString("http://server:8080/service", "POST", data);
});
}
Am I missing something here? Any idea would be helpful... ;-)
Kind regards,
Sebastian
I just found the reason for this.
It's the 100-Expect Continue HTTP Header and the corresponding implementation in .NET. The .NET client wait 350ms as default on the server. This causes the delays. Java seems to have other default values here...
Just add the following line of code very early in your code:
System.Net.ServicePointManager.Expect100Continue = false;
Cheers!

Categories

Resources