I am writing a spring boot application which reads messages from SQS. I am able to run the application using environment variables AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
. However, I was wondering it would be simpler to pass this configuration via a file similar to application.properties
. How to achieve this?
To prevent the SDK from requiring the credentials, you need to use the makeUnauthenticatedRequest method to place any calls. This allows you to call "an operation on a service with the given input parameters, without any authentication data". var AWS = require('aws-sdk'); AWS.
Assume role with profile You can configure the AWS SDK for PHP to use an IAM role by defining a profile for the role in ~/. aws/credentials . Create a new profile with the role_arn for the role you will assume. Also include the source_profile of a profile with credentials that have permissions to assume the IAM role.
Amazon Web Services offers multiple ways to install Spring Boot-based applications, either as traditional web applications (war) or as executable jar files with an embedded web server. The options include: AWS Elastic Beanstalk. AWS Code Deploy.
In spring boot application you can access properties mentioned in application.yml
file with @value
annotation. You can create a service like this:
@Service
public class AmazonClient {
private AmazonSQS sqsClient;
@Value("${amazonProperties.accessKey}")
private String accessKey;
@Value("${amazonProperties.secretKey}")
private String secretKey;
@PostConstruct
private void initializeAmazon() {
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(this.accessKey, this.secretKey);
this.sqsClient = AmazonSQSClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();
}
}
In application.yml
file:
amazonProperties:
accessKey: <your_access_key>
secretKey: <your_secret_key>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With