[AWS & Spring boot Error/Bug solve] com.amazonaws.services.kms.model.AWSKMSException / The security token included in the request is invalid. Service: AWSKMS; Status Code 400; Error Code UnrecognizedClientException



1. Problem

When i use aws cli, i set configure file ~/.aws/config. I set my aws profile and region/aws_access_key. But, when i try to use aws cli, i get error like under command. There is no problem on my aws access key, but i see this problem.

2022:06:01 20:05:51.311 INFO  --- [background-preinit] o.h.validator.internal.util.Version : HV000001: Hibernate Validator 6.1.7.Final 
2022:06:01 20:05:51.866 WARN  --- [main] c.a.a.p.i.BasicProfileConfigLoader : Your profile name includes a 'profile ' prefix. This is considered part of the profile name in the Java SDK, so you will need to include this prefix in your profile name when you reference this profile from your Java code. 
2022:06:01 20:05:52.069 WARN  --- [main] c.a.a.p.i.BasicProfileConfigLoader : Your profile name includes a 'profile ' prefix. This is considered part of the profile name in the Java SDK, so you will need to include this prefix in your profile name when you reference this profile from your Java code. 
2022:06:01 20:05:52.084 WARN  --- [main] c.a.a.p.i.BasicProfileConfigLoader : Your profile name includes a 'profile ' prefix. This is considered part of the profile name in the Java SDK, so you will need to include this prefix in your profile name when you reference this profile from your Java code. 

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.9.RELEASE)

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.fasterxml.jackson.databind.util.ClassUtil (file:/Users/user/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.11.4/ba123143d497f0a6465c764fad4/jackson-databind-2.11.4.jar) to field java.lang.Throwable.cause
WARNING: Please consider reporting this to the maintainers of com.fasterxml.jackson.databind.util.ClassUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2022:06:01 20:05:52.774 WARN  --- [main] o.s.c.b.e.EnvironmentDecryptApplicationInitializer : Cannot decrypt: key=spring.datasource.main.jdbc-url 
2022:06:01 20:05:52.791 ERROR --- [main] o.s.boot.SpringApplication : Application run failed 
java.lang.IllegalStateException: Cannot decrypt: key=spring.datasource.main.jdbc-url
	at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:292)
	at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.lambda$decrypt$0(EnvironmentDecryptApplicationInitializer.java:270)
	at java.base/java.util.LinkedHashMap.replaceAll(LinkedHashMap.java:694)
	at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:265)
	at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:190)
	at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.initialize(EnvironmentDecryptApplicationInitializer.java:124)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener$DelegatingEnvironmentDecryptApplicationInitializer.initialize(BootstrapApplicationListener.java:441)
	at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:626)
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:370)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
	at net.class101.classmate.ClassmateApplication.main(ClassmateApplication.java:61)
Caused by: com.amazonaws.services.kms.model.AWSKMSException: The security token included in the request is invalid. (Service: AWSKMS; Status Code: 400; Error Code: UnrecognizedClientException; Request ID: 1231-123-33-313-123214124; Proxy: null)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1819)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1403)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1372)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1145)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:802)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:770)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:744)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:704)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:686)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:550)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:530)
	at com.amazonaws.services.kms.AWSKMSClient.doInvoke(AWSKMSClient.java:7223)
	at com.amazonaws.services.kms.AWSKMSClient.invoke(AWSKMSClient.java:7190)
	at com.amazonaws.services.kms.AWSKMSClient.invoke(AWSKMSClient.java:7179)
	at com.amazonaws.services.kms.AWSKMSClient.executeDecrypt(AWSKMSClient.java:1775)
	at com.amazonaws.services.kms.AWSKMSClient.decrypt(AWSKMSClient.java:1744)
	at de.zalando.spring.cloud.config.aws.kms.KmsTextEncryptor.decrypt(KmsTextEncryptor.java:108)
	at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:277)
	... 10 common frames omitted

종료 코드 1(으)로 완료된 프로세스

2. Solution

In my case, i solve this problem change profile setting to default. I see under sentence and think “The Spring project cannot configure profile setting well”.

c.a.a.p.i.BasicProfileConfigLoader : Your profile name includes a ‘profile ‘ prefix. This is considered part of the profile name in the Java SDK, so you will need to include this prefix in your profile name when you reference this profile from your Java code.

So, i change profile setting to default. This can solve this problem :)

If you have this problem, i think you have these solution.

  • Solution
    • Change profile setting to default
    • Confirm project aws command doesn’t call profile setting