Skip to content

Commit df42119

Browse files
committed
feat:aws S3 셋팅
1 parent 6739e0d commit df42119

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ dependencies {
4848
implementation("org.springframework.boot:spring-boot-starter-data-redis")
4949
implementation("org.springframework.session:spring-session-data-redis")
5050

51+
// AWS S3
52+
implementation("io.awspring.cloud:spring-cloud-aws-starter-s3:3.4.0")
53+
5154
runtimeOnly("com.h2database:h2")
5255
runtimeOnly("com.mysql:mysql-connector-j")
5356

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.back.global.file;
2+
3+
import com.back.global.rsData.RsData;
4+
import io.swagger.v3.oas.annotations.Operation;
5+
import io.swagger.v3.oas.annotations.tags.Tag;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
import software.amazon.awssdk.services.s3.S3Client;
11+
import software.amazon.awssdk.services.s3.model.Bucket;
12+
13+
import java.util.List;
14+
import java.util.stream.Collectors;
15+
16+
17+
@Tag(name = "File", description = "file API")
18+
@RestController
19+
@RequestMapping("/file")
20+
@RequiredArgsConstructor
21+
public class FileController {
22+
private final S3Client s3Client;
23+
24+
@Operation(summary = "S3 버킷 목록 조회", description = "모든 버킷 목록을 조회")
25+
@GetMapping("/buckets")
26+
public RsData<List<String>> listBuckets() {
27+
28+
return RsData.of(
29+
200,
30+
"버킷 목록 조회",
31+
s3Client
32+
.listBuckets()
33+
.buckets()
34+
.stream()
35+
.map(Bucket::name)
36+
.collect(Collectors.toList())
37+
);
38+
39+
}
40+
}

terraform/main.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,41 @@ resource "aws_iam_instance_profile" "instance_profile_1" {
184184
}
185185
}
186186

187+
# S3 버킷 설정 추가
188+
resource "aws_s3_bucket" "app_bucket" {
189+
bucket = "${var.prefix}-${var.s3_bucket_name}"
190+
191+
tags = {
192+
Name = "${var.prefix}-${var.s3_bucket_name}"
193+
}
194+
}
195+
196+
resource "aws_s3_bucket_public_access_block" "app_bucket_pab" {
197+
bucket = aws_s3_bucket.app_bucket.id
198+
199+
block_public_acls = false
200+
block_public_policy = false
201+
ignore_public_acls = false
202+
restrict_public_buckets = false
203+
}
204+
205+
resource "aws_s3_bucket_policy" "app_bucket_policy" {
206+
bucket = aws_s3_bucket.app_bucket.id
207+
208+
policy = jsonencode({
209+
Version = "2012-10-17"
210+
Statement = [
211+
{
212+
Effect = "Allow"
213+
Principal = "*"
214+
Action = "s3:GetObject"
215+
Resource = "${aws_s3_bucket.app_bucket.arn}/*"
216+
}
217+
]
218+
})
219+
}
220+
221+
187222
locals {
188223
ec2_user_data_base = <<-END_OF_FILE
189224
#!/bin/bash

terraform/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,15 @@ variable "prefix" {
1818
variable "app_1_domain" {
1919
description = "app_1 domain"
2020
default = "api.ssoul.o-r.kr"
21+
}
22+
23+
variable "s3_bucket_name" {
24+
description = "S3 bucket name for file storage"
25+
default = "app-s3-bucket"
26+
}
2127

28+
variable "s3_public_read" {
29+
description = "Enable public read access for S3 bucket"
30+
type = bool
31+
default = true
2232
}

0 commit comments

Comments
 (0)