Reputation: 2086
I want to Send an Email with Amazon SES and SpringBoot, I have this config file:
@Configuration
public class MailConfig {
@Bean
public AmazonSimpleEmailService amazonSimpleEmailService() {
return AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(new ProfileCredentialsProvider("ses-smtp-user.2024321-167419"))
.withRegion(Regions.EU_WEST_2)
.build();
}
@Bean("myMailSender")
public MailSender mailSender(
AmazonSimpleEmailService amazonSimpleEmailService) {
return new SimpleEmailServiceMailSender(amazonSimpleEmailService);
}
}
using the field IAM User name from the credentials:
but I have this error when starting the app:
Caused by: java.lang.IllegalArgumentException: No AWS profile named 'ses-smtp-user.20211221-172419'
Upvotes: 0
Views: 2440
Reputation: 200562
The string you pass to ProfileCredentialsProvider()
is a local profile name, that should be a name present in your local .aws/credentials
file. You're trying to pass it an IAM user name, which is a totally different thing.
First, I suggest you read the documentation.
Second, I suggest you use environment variables instead of hard-coding any sort of credential settings in your code. You can either set the AWS_PROFILE
environment variable, or set the AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
environment variables, and then your code would look like this:
return AmazonSimpleEmailServiceClientBuilder.standard()
.withRegion(Regions.EU_WEST_2)
.build();
And in addition to being cleaner and simpler code, it will also automatically use the environment's assigned IAM role when running on EC2, ECS, Lambda, etc..
Upvotes: 1