0

In december I had my first fullstack project working, that means it worked on my mac in school and on the deployed app. Now that I cloned my repo onto my own windows machine, I have some problems getting everything back up and running in the dev environment. Basically I am uploading and retrieving images into/from an S3 bucket and the deployed app is in a docker container in another bucket.

I am using IntelliJ Idea Ultimate 2020.3 and Java with Spring Boot and lombok.

I have one class that is supposed to handle the AWS Credentials and Client and is making me a lot of headaches.

@Configuration
public class AmazonS3ClientUtils {

    @Value("${aws.access.key}")
    private String accessKey;

    @Value("${aws.secret.key}")
    private String secretKey;

    private final Regions clientRegion = Regions.EU_CENTRAL_1;

    @Bean
    public BasicAWSCredentials getAwsCredentials() {
        return new BasicAWSCredentials(accessKey, secretKey);
    }

    @Bean
    public AmazonS3 getS3Client() {

        return AmazonS3ClientBuilder.standard()
                .withRegion(clientRegion)
                .withCredentials(new InstanceProfileCredentialsProvider(true))
                .build();
    }

}

and I also have an application.yml file in my ressources looking like this:

spring:
  data:
    mongodb:
      database: gramf
aws:
  access.key: testkey
  secret.key: testkey
  bucket.name: testbucket

management:
  endpoints:
    enabled-by-default: false
  endpoint:
    health:
      enabled: true

I also have the .aws folder with a credentials and a config file. The config fle:

[default]
aws_access_key_id = [accessKey]
aws_secret_access_key = [secretKey]
region = eu-central-1
output = json
aws_bucket_name = bucket-for-images

Yes, the brackets in line 2 and 3 are there. This is my credentials file:

[default]
aws_access_key_id = *<here is my access key>*
aws_secret_access_key = *<here is my secret access key>*

This is like I cloned it from my repo, where the recent working version was pushed in december. In december on my schools mac it worked exactly like this. I simply cloned it, set up the credential and config file and started the dev server and my frontend. As soon as my frontend loads, my browsers console shows me error 500 and the run console in IntelliJ shows this https://gist.github.com/077dede08ad2befeb2b3d1c93657d134

When I go into my AmazonS3ClientBuilderand remove the line .withCredentials(new InstanceProfileCredentialsProvider(true)) I don´t get a 500 anymore, and the IntelliJ run console stays clean. Now I am only left with another error in the browsers console, a cross origin read blocking, because my image url has testbucketin it instead of the correct bucket name.

Cross-Origin Read Blocking (CORB) blocked cross-origin response 
https://testbucket.s3.eu-central-1.amazonaws.com/... with MIME type application/xml. 

So now I can go on and put the correct bucketname in application.yml and my app will work locally without errors.

But why the hell did this code work on the mac and not on my windows machine? And what did .withCredentials(new InstanceProfileCredentialsProvider(true)) do? Will I break my app when I am going do deploy a new version to AWS without this?

I can also add my aws keys to the application.yml, but this does not make any difference at all. .withCredentials(new InstanceProfileCredentialsProvider(true)) in the code will still cause an error. When I understand this right, the @Value("${aws.access.key}")annotation is looking into the application.ymlfor the variables. Why is it working when the yml only has testkeyin it instead of the real keys? And if that somehow redirects to the ´.aws/config´ / .aws/credentials , why does it not accept the aws_bucket_name from there, only the keys?

My file structure is looking like this: C:\Users\username\IdeaProjects\project-git-clone i can eb status here with Ready and Green as result, but not in any folder below this

inside of the folder project-git-clone are the subfolders .idea and the-project, inside the-projectis my .elasticbeanstalk/config.yml and my backend and frontend folder and the Dockerfile Might it be, that the AWS EB CLI is providing some of these credential informations and I did use eb init one folder too high?

Thank you for reading, if someone knows some answers I would be so happy!

Dennis
  • 33
  • 6
  • If you are using `instanceProfile` then you should be running on AWS Cloud. In the local machine, you should use keys. – Kumaresh Babu N S Feb 16 '21 at 08:35
  • Yes, the deployed version is running in an EC2 instance, which can identify itself to the S3 bucket in which the images are and vice versa. – Dennis Feb 16 '21 at 20:08

0 Answers0