Below code creates AWS Credentials where access and secret keys are explicitly supplied.
AWSCredentials credentials = new BasicAWSCredentials(
"<AWS accesskey>",
"<AWS secretkey>"
);
But the issue with this approach is in production I can not use it. So what will be an equivalent java code that will obtain credential automatically from the aws credentials chain and create a credential object or some EC2 client.