• Home
  • About
    • Mayaul photo

      Mayaul

      hello woooooorld.

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

spring-cloud-aws-context

16 Feb 2020

Reading time ~1 minute

AmazonSNS, AmazonSQS bean 을 자체 생성시에는 bean 의 이름 중 SNS, SQS 는 꼭 대문자

  • 대표적으로 SnsConfiguration 을 보면, 아래와 같이 @ConditionalOnMissingAmazonClient(AmazonSNS.class) 으로 검사를 하고 있습니다.
@Configuration
public class SnsConfiguration {

	@Autowired(required = false)
	private AWSCredentialsProvider awsCredentialsProvider;

	@Autowired(required = false)
	private RegionProvider regionProvider;

	@ConditionalOnMissingAmazonClient(AmazonSNS.class)
	@Bean
	public AmazonWebserviceClientFactoryBean<AmazonSNSClient> amazonSNS() {
		return new AmazonWebserviceClientFactoryBean<>(AmazonSNSClient.class,
				this.awsCredentialsProvider, this.regionProvider);
	}

}
  • 일반적으로 Spring framework 에서 보던 @ConditionalOnMissingBean 이 아닙니다.
  • @ConditionalOnMissingAmazonClient 를 따라가보면 아래와 같이 설명이 있습니다.
/**
* <p>
* The Amazon clients that needs to be available in order to match the condition.
* </p>
*
* <b>IMPORTANT</b>: This condition does not verify the presence of a client, based on
* the type, but based on the default name as computed in
* {@link org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils#getBeanName}.
* @return Amazon client class
*/
  • bean 의 이름으로 중복된 bean 이 있는지 검사를 한다고 되어있습니다.
  • 같은 타입의 이름을 다르게 bean 을 만들었다면, 중복으로 bean 을 만들게 되어 에러가 발생이 될 수 있습니다. 관련된 에러 발생시 이름을 확인 해야 할 것 같습니다.

기본으로 설정되는 region 정보

  • spring-cloud-aws-context 에서 region 의 정보를 설정하는 방법은 다양하게 있습니다.

  • source code 로 지정
    @Bean
    public AmazonSQSBufferedAsyncClient amazonSqs() {
      return new AmazonSQSBufferedAsyncClient(
          AmazonSQSAsyncClientBuilder
              .standard()
              .withRegion(Regions.AP_NORTHEAST_2)
              .build()
      );
    }
    
  • spring-cloud-aws-context 에서 기본적으로 생성해주는 bean 사용시
    • yml 에 설정
      cloud.aws.region.static: ap-northeast-2
      
    • yml 설정된 내역이 없다면, 기본적으로 ec2 의 region 정보를 설정


awsspring-cloudspring-cloud-aws-contextbean Share Tweet +1