Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”ง EC2 ์„œ๋ฒ„์—์„œ AWS ๊ถŒํ•œ ์ธ์ฆ ๋ฐฉ์‹ #38

Open
psychology50 opened this issue Apr 9, 2024 · 1 comment
Assignees
Labels
discussion ๊ธด๊ธ‰ํ•˜์ง€ ์•Š๊ณ , ์ค‘์š”๋„๊ฐ€ ๋‚ฎ์€ ์ด์Šˆ

Comments

@psychology50
Copy link
Member

๋…ผ์˜ ์ฃผ์ œ

  • AWS access key, refresh key ์ฃผ์ž… ๋ฐฉ์‹์— ๋Œ€ํ•ด์„œ

๋…ผ์˜ ๋‚ด์šฉ

  • ํ˜„์žฌ AWS Config ๊ถŒํ•œ ์„ค์ • ๋ฐฉ์‹์€ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ฃผ์ž…ํ•˜์—ฌ ์ธ์ฆํ•จ.
@Getter
@Configuration
public class AwsSnsConfig {
    private final String accessKey;
    private final String secretKey;
    private final String region;

    public AwsSnsConfig(
            @Value("${spring.cloud.aws.sns.credentials.access-key}") String accessKey,
            @Value("${spring.cloud.aws.sns.credentials.secret-key}") String secretKey,
            @Value("${spring.cloud.aws.sns.region.static}") String region
    ) {
        this.accessKey = accessKey;
        this.secretKey = secretKey;
        this.region = region;
    }

    @Bean
    public AwsCredentials awsSnsCredentials() {
        return AwsBasicCredentials.create(accessKey, secretKey);
    }

    ...
}
  • ํ•˜์ง€๋งŒ AWS ๊ถŒ๊ณ  ์‚ฌํ•ญ์— ๋”ฐ๋ฅด๋ฉด EC2 ์„œ๋ฒ„์—์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ธ์ฆ์„ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
@Configuration
public class AwsConfiguration {
    @Value("${cloud.aws.credentials.access-key}")
    private String awsAccessKey;

    @Value("${cloud.aws.credentials.secret-key}")
    private String awsSecretKey;

    @Value("${cloud.aws.region.static}")
    private String region;

    @Value("${spring.profiles.active:}")
    private String activeProfile;

    @Bean
    public AmazonSNSClient amazonSNSClient(Environment environment ) {
        if(StringUtils.equals(activeProfile , "")){
            return (AmazonSNSClient) AmazonSNSClientBuilder
                    .standard()
                    .withRegion(region)
                    .withCredentials(InstanceProfileCredentialsProvider.getInstance())
                    .build();
        }else{
            return (AmazonSNSClient) AmazonSNSClientBuilder
                    .standard()
                    .withRegion(region)
                    .withCredentials(new AWSStaticCredentialsProvider(
                            new BasicAWSCredentials(environment.getProperty("cloud.aws.credentials.access-key"), environment.getProperty("cloud.aws.credentials.secret-key"))))
                    .build();
        }
    }
}

๋”ฐ๋ผ์„œ ์ถ”ํ›„ ์œ„์˜ ๋ฐฉ์‹๋Œ€๋กœ ๋ณ€๊ฒฝํ•ด๋ณด๊ณ ์ž ํ•˜๋Š”๋ฐ, ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”?

@psychology50 psychology50 added the discussion ๊ธด๊ธ‰ํ•˜์ง€ ์•Š๊ณ , ์ค‘์š”๋„๊ฐ€ ๋‚ฎ์€ ์ด์Šˆ label Apr 9, 2024
@asn6878
Copy link
Member
asn6878 commented Apr 9, 2024

๋กœ์ปฌ์—์„œ Spring Boot ์‹คํ–‰ VS EC2 ์ธ์Šคํ„ด์Šค์—์„œ Spring boot ์‹คํ–‰ ์„ ํŒ๋‹จ ํ›„
์ƒํ™ฉ์— ๋งž์ถ”์–ด์„œ ํ‚ค๊ฐ’ ์ฃผ์ž… ๋ฐฉ์‹(ํ™˜๊ฒฝ๋ณ€์ˆ˜ vs InstanceProfileCredentialsProvider)์„ ๋ถ„๊ธฐํ•ด์ฃผ๋Š”๊ฑธ๋กœ ์ดํ•ดํ–ˆ๋Š”๋ฐ, ๋งž์„๊นŒ์š”?

๊ตณ์ด ์ด์œ ๊ฐ€์—†๋‹ค๋ฉด ๊ถŒ๊ณ ํ•˜๋Š” ๋ฐฉ์‹์— ๋งž์ถ”์–ด ์ฃผ๋Š”๊ฒŒ ์ผ๋‹จ ์ข‹๋‹ค๋Š” ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion ๊ธด๊ธ‰ํ•˜์ง€ ์•Š๊ณ , ์ค‘์š”๋„๊ฐ€ ๋‚ฎ์€ ์ด์Šˆ
Projects
None yet
Development

No branches or pull requests

3 participants