title: How to Connect to S3 bucket using policy without keys through Java
body: <p>I have a policy something like </p>
  
  <pre><code>{
  "Id":"Pid6",
  "Version": "2012-10-17",
  "Statement": [
      {
          "Effect": "Allow",
          "Action": "s3:PutObject",
          "Action": "s3:GetObject",
          "Action": "s3:ListBucket",
          "Resource": [
                       "arn:aws:s3:::test-bucket",
                       "arn:aws:s3:::test-bucket/*"
                      ]
      }
    ]
  }
  </code></pre>
  
  <p>My Java code to connect to S3 bucket is </p>
  
  <pre><code>BasicAWSCredentials awsCreds = new BasicAWSCredentials("accessKey", "secretKey");
  AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
              .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
              .withRegion(Regions.region).build();
  s3Client.putObject( new PutObjectRequest( S3_BUCKET, s3Path, file )
              .withCannedAcl( CannedAccessControlList.PublicRead ) );
  </code></pre>
  
  <p>I am able to connect to s3 using access key &amp; secret key...
  How can I connect to s3 bucket using policy without the need for key based access using Java.
  I mean how to get <code>s3Client</code> object or <code>awsCreds</code> object using <code>policy.json</code> file</p>