• Latest
Integrate AWS Secrets Manager in Spring Boot Application

Integrate AWS Secrets Manager in Spring Boot Application

March 21, 2023
8 Proven Ways to Combat End-of-Life Software Risks

8 Proven Ways to Combat End-of-Life Software Risks

March 30, 2023

The Best Smartphone Camera 2022!

March 30, 2023
Yes, The Super Mario Bros. Movie Will Have A Post-Credits Scene

Yes, The Super Mario Bros. Movie Will Have A Post-Credits Scene

March 30, 2023
Main sirf Allah ke Aage jhukne wala hon #shorts#aimim

Main sirf Allah ke Aage jhukne wala hon #shorts#aimim

March 30, 2023
Check out BLUETTI’s new AC60 solar generator and B80 battery

Check out BLUETTI’s new AC60 solar generator and B80 battery

March 30, 2023
Horizon Forbidden West Expansion’s Impressive Cloud Tech Is a Big Reason It’s PS5 Only

Horizon Forbidden West Expansion’s Impressive Cloud Tech Is a Big Reason It’s PS5 Only

March 30, 2023
ulama e deoband zindabaad #shorts #ulmaedeoband

ulama e deoband zindabaad #shorts #ulmaedeoband

March 30, 2023
Why I bought the Sony A95K in 2023?

Why I bought the Sony A95K in 2023?

March 30, 2023
Resident Evil 4 Remake Is a Love(craftian) Letter to My Favorite Monsters

Resident Evil 4 Remake Is a Love(craftian) Letter to My Favorite Monsters

March 30, 2023
RED HYDROGEN ONE – Unboxing By Marques Brownlee

RED HYDROGEN ONE – Unboxing By Marques Brownlee

March 30, 2023
Lost Apple Watch survives the sea and is returned to its owner

Lost Apple Watch survives the sea and is returned to its owner

March 30, 2023
Celebrate Silliness With The Return Of Elder Scrolls Online’s Jester’s Festival

Celebrate Silliness With The Return Of Elder Scrolls Online’s Jester’s Festival

March 30, 2023
Advertise with us
Thursday, March 30, 2023
Bookmarks
  • Login
  • Register
GetUpdated
  • Game Updates
  • Mobile Gaming
  • Playstation News
  • Xbox News
  • Switch News
  • MMORPG
  • Game News
  • IGN
  • Retro Gaming
  • Tech News
  • Apple Updates
  • Jailbreak News
  • Mobile News
  • Software Development
  • Photography
  • Contact
No Result
View All Result
GetUpdated
No Result
View All Result
GetUpdated
No Result
View All Result
ADVERTISEMENT

Integrate AWS Secrets Manager in Spring Boot Application

March 21, 2023
in Software Development
Reading Time:6 mins read
0 0
0
Share on FacebookShare on WhatsAppShare on Twitter


Introduction

In this article, we will understand the integration of AWS Secrets Manager in the Spring Boot Application. This service will load the secrets at runtime and make sure to keep the sensitive information away from the code.

Context

When we work on a Spring Boot Application, we have an application.properties file based on the different profiles (environment). In these files, we keep all the information related to the configuration of the Spring Boot application. The file contains database credentials and other sensitive information like any credentials or ftp server’s endpoint along with credentials. This sensitive information is not recommended to be put directly into the code for security concerns. To avoid such vulnerabilities in our application, we have to take several measures in order to ensure the security of sensitive information.

There are several ways to secure this information. We can define server arguments to load such details, and other ways are there too. As we are using AWS, there is a service available for the same. The service of AWS which we can use to store sensitive information and credentials is Secrets Manager. In this document, we will see how to integrate the AWS Secrets Manager and load all the secrets at the runtime and make our application secure.

What Is AWS Secrets Manager?

AWS Secrets Manager is an AWS service that makes it easier for you to manage secrets. Secrets can be database credentials, passwords, third-party API keys, and even arbitrary text. You can store and control access to these secrets centrally by using the Secrets Manager console, the Secrets Manager command-line interface (CLI), or the Secrets Manager API and SDKs.

Secrets Manager

Let’s create the secrets first.

In order to create the secrets, we need to log in to our AWS Console, and there, we have to search for the Secrets Manager in the service lists.

search for the Secrets Manager in the service list

Now, we have to create new secrets by simply selecting the following type from the selection options, and we can create secrets there in the form of key and value. Here, we can add any number of secrets we want for our purpose.

Choose secret type

After creating all the secrets in the key-value pair, we have to click next, and we have to provide the name of the secret. By this name only, we can retrieve the values in our application. 

Provide name and description

Once we complete this step, we will click on next, and there it will ask for a couple of configuration-related things which we have to select as per our requirement. If we want simple storage of secrets, we will let other configurations as it is and will move to the final screen of setting up the AWS secrets.

Sample code

After successfully storing the secrets, we will now move to our Spring Boot application to retrieve the secrets there. In order to integrate the AWS Secrets Manager in our application, we need to add the Secrets Manager dependency in our pom.xml

In this article, we are using Spring Boot 2.7.3 version. Add the below dependency in the pom.xml as it is compatible with this version. You can change the version of dependency based on the version of your Spring Boot application.

<dependency>
	<groupId>io.awspring.cloud</groupId>
	<artifactId>spring-cloud-starter-aws-secrets-manager-config</artifactId>
	<version>2.3.0</version>
</dependency>

Note: The groupId for the secrets manager is changed. Earlier, it was org.springframework.cloud

Once you add the above dependency, now you have to import the secrets into our application. In this approach, we will be loading all the secrets at the bootstrap time of our application. The advantage of using this approach is that all the secrets will be available at the bootstrap time, and the information which is needed for the configuration in Spring Boot, such as database credentials and information needed in order to create beans, will be available. We need to add the below line in our application.properties file in order to import all the secrets.

spring.config.import= aws-secretsmanager: shs-portal-dev

In this config, we are simply importing the secrets from AWS. The prefix aws-secretsmanager is needed in order to tell spring to load the config from AWS. In case the secrets are not available, we do not want our application to fail at the bootstrap, so we will add optional in the below manner to make the import optional.

spring.config.import= optional:aws-secretsmanager: shs-portal-dev

Once this is done, we will start our Spring Boot application, and we will find the below line in the console. This line tells us that spring is loading the secrets from AWS Secrets Manager.

spring in loading

As we have seen, the following line in our logs ensures that secrets have been loaded successfully. In order to use them, we must use $ and {} to retrieve the value wherever needed.

secrets loaded successfully

We can also retrieve the values in java code with the help of @Value annotation.

Note: If there is any error coming in regards to the bootstrap class in logs and the application fails to start, use the exclusion given below with the secrets manager dependency.

<dependency>
	<groupId>io.awspring.cloud</groupId>
	<artifactId>spring-cloud-starter-aws-secrets-manager-config</artifactId>
	<version>2.3.0</version>
	<exclusion>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-context</artifactId>
	</exclusion>
</dependency>



Source link

ShareSendTweet
Previous Post

Marques Brownlee Unboxing Mystery Items

Next Post

Marques Brownlee/MKBHD Answers Reddit Questions (r/IAmA)

Related Posts

8 Proven Ways to Combat End-of-Life Software Risks

March 30, 2023
0
0
8 Proven Ways to Combat End-of-Life Software Risks
Software Development

Software has become an essential part of our daily lives, from the apps on our phones to the programs we...

Read more

Tackling the Top 5 Kubernetes Debugging Challenges

March 30, 2023
0
0
Tackling the Top 5 Kubernetes Debugging Challenges
Software Development

Cloud-native technologies like Kubernetes enable companies to build software quickly and scale effortlessly. However, debugging these Kubernetes-based applications can be...

Read more
Next Post
Marques Brownlee/MKBHD Answers Reddit Questions (r/IAmA)

Marques Brownlee/MKBHD Answers Reddit Questions (r/IAmA)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

© 2021 GetUpdated – MW.

  • About
  • Advertise
  • Privacy & Policy
  • Terms & Conditions
  • Contact

No Result
View All Result
  • Game Updates
  • Mobile Gaming
  • Playstation News
  • Xbox News
  • Switch News
  • MMORPG
  • Game News
  • IGN
  • Retro Gaming
  • Tech News
  • Apple Updates
  • Jailbreak News
  • Mobile News
  • Software Development
  • Photography
  • Contact

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?