1

Check the below image as I already set the Environment Variable with ACCESS and SECRET Key into CodeBuild AWS. enter image description here And I am trying to get those data into JAVA Project with the below code but unable to get value and get null output.

    String access_key = System.getenv("AWS_ACCESS_KEY_ID");
    String secret_key = System.getenv("AWS_SECRET_ACCESS_KEY");
    
    System.err.println("access_key " + access_key);
    System.err.println("secret_key " + secret_key);

Also tried with the below way but was unable to get the value of it.

System.err.println("Access key: "+StringParameter.valueFromLookup(this,"AWS_ACCESS_KEY_ID");

Also did the below way but did not get any success.

System.err.println("Access : "+EnvironmentVariableCredentialsProvider.create().resolveCredentials().accessKeyId());

Thanks in advance.

Jyubin Patel
  • 1,373
  • 7
  • 17
  • 1
    It goes beyond the question, but you NEVER share your AWS ACCESS KEY and SECRET KEY, moreover you never store them anywhere as plaintext, besides you local machine. If you need AWS access, you rely on giving the necessary roles and permissions to the services which runs your code. Afterwards, in your code you use the default credentials provider chain: https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html which will be able to fetch the necessary authentication tokens. – Ervin Szilagyi Dec 30 '21 at 13:18
  • @ErvinSzilagyi It's working fine in my local system but it is not working in the AWS machine so need access and a secret key from the environment variable and use it for further tasks. – Jyubin Patel Dec 30 '21 at 13:23
  • Is this Java code being invoked by CodeBuild, or is it being built by CodeBuild and invoked elsewhere? – Parsifal Dec 30 '21 at 13:39
  • @Parsifal Code execution is invoked in code build not else where. – Jyubin Patel Dec 30 '21 at 13:41
  • Can you show the CodeBuild script that you're running? As text, not a picture. – Parsifal Dec 30 '21 at 13:45
  • You shouldn't do this. Instead, you should grant the necessary rights to the codebuild action's role. – gshpychka Dec 30 '21 at 15:43

0 Answers0