I have created a Spring boot application where I want to use AWS secrets for application.properties. I am using spring boot 2.2.6.RELEASE and as per the documentation I have added following dependencies in my pom:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws-secrets-manager-config</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
From AWS Secrets Manager service I created a new secret of type "Other types of secrets" and gave it a name /secret/myservice. For testing I added a secret key as environment and value as aws which I want to retrieve in my controller. The part which is not clear to me is the entry I need to make in my bootstrap.yml file as I am confused with the instructions in Spring Cloud AWS documentation. Could someone please provide some proper instructions as I am not able to use this feature properly. For reference I added this in my bootstrap.yml file:
aws:
secretsmanager:
name: myservice
prefix: /secret
enabled: true
defaultContext: application
failFast: true
cloud:
aws:
region:
static: us-east-1
and trying to retrieve the environment value in the controller:
@RestController
@EnableWebMvc
public class PingController {
@Value(value = "${environment}")
private String environment;
@RequestMapping(path = "/ping", method = RequestMethod.GET)
public Map<String, String> ping() {
Map<String, String> pong = new HashMap<>();
pong.put("pong", "Hello, World!" + "This is " + environment + " environment...");
return pong;
}
}
Struggled with the same problem. Solved this by defining environment variables in the lambda function itself and then populating those with AWS Secrets Manager.
This way you can use a placeholder like ${property_1} in the application.properties file and this will be replaced by the Environment variable defined in the Lambda Function.