-
-
Save PedroAvila/2da95fc4e07b1795c93768e5d209f602 to your computer and use it in GitHub Desktop.
Configuracion del archivo properties y del bucket de AWS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| spring: | |
| datasource: | |
| url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE | |
| driverClassName: org.h2.Driver | |
| username: sa | |
| password: | |
| Te paras en el bucket que creates en la pestaña permisos al final creas este json con el nombre de tu bucket | |
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Sid": "PublicReadForObjects", | |
| "Effect": "Allow", | |
| "Principal": "*", | |
| "Action": "s3:GetObject", | |
| "Resource": "arn:aws:s3:::springboots3bucket46/*" | |
| } | |
| ] | |
| } | |
| Bean Configuration | |
| @Configuration | |
| public class S3Config { | |
| // Asumiendo que has configurado estas propiedades en application.yml | |
| @Value("${cloud.aws.credentials.access-key}") | |
| private String accessKey; | |
| @Value("${cloud.aws.credentials.secret-key}") | |
| private String secretKey; | |
| @Value("${cloud.aws.region.static}") | |
| private String region; | |
| @Bean | |
| public AmazonS3Client s3Client() { | |
| // 1. Crear el objeto de credenciales usando las claves del yml | |
| AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); | |
| // 2. Construir y devolver el cliente de S3 | |
| return (AmazonS3Client) AmazonS3ClientBuilder.standard() | |
| .withCredentials(new AWSStaticCredentialsProvider(credentials)) | |
| .withRegion(region) | |
| .build(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment