How about a null check on s3Object before getting the input stream. Though chances are less, getObject returns null on invalid key which will cause NPE in this case.