Hot questions for Using Amazon S3 in tomcat


I'm very new to AWS (today is the second day of my free trial). I've created elastic beanstalk application (using Tomcat server) and deployed very simple java web-app (1 static page & 1 jsp generated by servlet). I'm not using any AWS api or so on, just upload war file to EB project. When I see my statistic there is S3 - Puts and S3 - Gets usage.

Between this screenshots I've just once opened my web-app, but S3 usage still growing(:

How to know where my application use S3, and how to prevent this?

Thank you in advance!


Elastic Beanstalk stores application deployment artifacts on S3. Elastic Beanstalk also archives application logs to S3. It should be extremely easy for you to open the S3 console and look at the S3 buckets and objects in your account to see what is going on.


In my local I am successfully able to point my docBase like this - <Context docBase="D:/XYZ" path="/video" />.

Since my Java based application is going to be hosted on AWS, I am using Amazon ec2 to deploy my application and Amazon S3 to host the videos, thumbnails and profile photos of the users. So I changed my tomcat 7 server.xml entry on ec2 to <Context docBase="http://MyS3EndPointURL" path="/videos" />

However when I am trying to restart my tomcat, it errors out saying -

java.lang.IllegalArgumentException: Document base /usr/share/tomcat7/webapps/MyS3EndPointURL/Videos does not exist or is not a readable directory

I tried removing http:// but as I expected it didn't work as well.

I understand that I will have to give permission to Tomcat to have access to these folders, however I have these questions -

  1. How do I provide this access ?
  2. When a user uploads a video will my application have the write access to these folders ? If no, how to provide that ?

From whatever reference articles are available on AWS, none talks about this issue. Stackoverflow question searches are mostly outdated information or people are suggesting to have another static domain. I am supposed to release the product this weekend in BETA mode but I am stuck because of this issue. Any pointers, suggestions would just save me !


If I understand your setup, your app is hosted on Tomcat, you want your users to upload content to S3, so you can refer to your assets via an S3 http endpoint.

If so, your app server configuration is incorrect. Your server will not serve any videos itself; that job is offloaded to S3. Rather than define a docBase as you have, you will want to provide a URL rewrite rule so that point s to the new S3 http endpoint EG

When a user uploads a video will my application have the write access to these folders ? If no, how to provide that.

If you have not already, you need to develop an upload interface with the appropriate permissions the the above bucket. See Java Upload File for more information


I'm using "aws-java-sdk-1.11.427.jar" in my code and tomcat is refusing to start and shows below error: But there is no compile time error..

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/api]]
    at java.util.concurrent.FutureTask.get(
    at org.apache.catalina.core.ContainerBase.startInternal(
    at org.apache.catalina.core.StandardHost.startInternal(
    at org.apache.catalina.util.LifecycleBase.start(
    at org.apache.catalina.core.ContainerBase$
    at org.apache.catalina.core.ContainerBase$
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/api]]
    at org.apache.catalina.util.LifecycleBase.start(
    ... 6 more
Caused by: java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(
    at java.lang.Class.getDeclaredFields(
    at org.apache.catalina.util.Introspection.getDeclaredFields(
    at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(
    at org.apache.catalina.startup.ContextConfig.configureStart(
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(
    at org.apache.catalina.core.StandardContext.startInternal(
    at org.apache.catalina.util.LifecycleBase.start(
    ... 6 more
Caused by: java.lang.ClassNotFoundException: com.amazonaws.auth.AWSCredentials
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(
    ... 19 more


Just put aws-java-sdk-1.11.427.jar in tomcat lib folder


I have written a code to list files in amazon s3 bucket , but it gives me this exception :

com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to [/] failed: Connection refused: connect
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Code to list files with main method:

public class App {

    String bucketName = "buketname";
    String accesskey = "accesskey";

    public static void main(String args[]) throws Exception {
        new App();


    App() throws Exception {

        BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accesskey,

        AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(basicAWSCredentials);

        AwsClientBuilder.EndpointConfiguration endpointConfiguration =
                new AwsClientBuilder.EndpointConfiguration("", "");

        ClientConfiguration clientCfg = new ClientConfiguration();
        SSLContextBuilder builder = new SSLContextBuilder();

        builder.loadTrustMaterial(null, new

                TrustStrategy() {
                    public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                        return true;

        SSLConnectionSocketFactory sslConnectionSocketFactory =
                new SSLConnectionSocketFactory(, new NoopHostnameVerifier());


        AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard()



public void listAllFiles(AmazonS3 amazonS3) {

        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName);

        ObjectListing objectListing = amazonS3. listObjects (listObjectsRequest);

                s3ObjectSummary -> {
                    System.out.println(s3ObjectSummary.getKey() + "  " + s3ObjectSummary.getSize());



This code will work fine if i run the code by executing the main method , but if i run the code from tomcat server by calling a Spring restful webservice then the exception will occur.

Currently i am using latest Tomcat server 8.5.28 , is there any way to fix this issue ?


EndpointConfiguration is for Amazon's endpoint, not yours. From the documentation:

Each AWS client can be configured to use a specific endpoint within a region by calling the setEndpoint method.

For example, to configure the Amazon EC2 client to use the EU (Ireland) Region, use the following code.

AmazonEC2 ec2 = new AmazonEC2(myCredentials);


I am attempting to set a property that contains $ in it as a Environmental Property (Configure -> Software -> Environment properties) that will eventually get passed to my tomcat context.xml file (all running on AMI - Tomcat 8 with Java 8 running on 64bit Amazon Linux/3.0.1). It seems like it won't accept $ characters (source: It appears that they are being interpreted as bash variables. Can I escape the $ some how, I've tried \$ and (double backslash)\$ with no luck. Am I missing something or am I just out of luck.



So with a bit or trial and error it looks like you need 3 backslashes to escape the $ character. \\\$myData