简体   繁体   English

使用 AWS SNS 的 Springboot

[英]Springboot with AWS SNS

Actually Iam trying to set email subscription to SNS topic in AWS through springboot and publish the message to SNS topic.实际上我正在尝试通过 springboot 在 AWS 中设置 email 订阅 SNS 主题并将消息发布到 SNS 主题。 But facing issue in configuring the AWS access key and secret key.但是在配置 AWS 访问密钥和密钥时面临问题。 Do I need to create a separate IAM user for accessing SNS or it is fine to have a IAM user already created with administrator access to SNS topic.我是否需要创建一个单独的 IAM 用户来访问 SNS,或者已经创建了一个具有 SNS 主题管理员访问权限的 IAM 用户就可以了。 Below is the configuration file I created.下面是我创建的配置文件。

@Configuration public class AmazonSNSConfiguration { @Configuration 公共 class AmazonSNSConfiguration {

@Bean
@Primary
public AmazonSNSClient amazonSNSClient() {
     return (AmazonSNSClient) AmazonSNSClientBuilder
                .standard()
                .withRegion(Regions.US_EAST_1)
                .withCredentials(
                        new AWSStaticCredentialsProvider(
                                new BasicAWSCredentials(
                                        "**********",
                                        "***********"
                                )
                        )
                )
                .build();
}

} }

When working with Spring BOOT and the Java SNS V2 API, you can create an IAM role that has a policy to use SNS.使用 Spring BOOT 和 Java SNS V2 API 时,您可以创建一个具有使用 SNS 策略的 IAM 角色。

Also, there is no reason to Hard Code the key creds in the Java code.此外,没有理由对 Java 代码中的密钥凭据进行硬编码。 You can create an SNSClient object like this:您可以像这样创建SNSClient object:

Region region = Region.US_WEST_2;
SnsClient snsClient = SnsClient.builder()
    .region(region)
    .build();

This code assumes you have set the creds in a file named credentials located in.aws.此代码假定您已在位于 .aws 中的名为 credentials 的文件中设置了 creds。 See this doc (under heading Configure credentials ) for more information:有关更多信息,请参阅此文档(在标题Configure credentials下):

Get started with the AWS SDK for Java 2.x 开始使用适用于 Java 2.x 的 AWS SDK

Here is an AWS developer tutorial that steps you through How To create a Spring BOOT app that uses the SNS service to create a Sub/Pub app:这是一个 AWS 开发人员教程,指导您完成如何创建 Spring BOOT 应用程序,该应用程序使用 SNS 服务创建 Sub/Pub 应用程序:

Creating a Publish/Subscription Spring Boot Application 创建发布/订阅 Spring 引导应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM