Search in sources :

Example 1 with S3Service

use of com.formkiq.aws.s3.S3Service in project formkiq-core by formkiq.

the class StagingS3CreateTest method beforeClass.

/**
 * Before Class.
 *
 * @throws URISyntaxException URISyntaxException
 * @throws InterruptedException InterruptedException
 * @throws IOException IOException
 */
@BeforeAll
public static void beforeClass() throws URISyntaxException, InterruptedException, IOException {
    Region region = Region.US_EAST_1;
    AwsCredentialsProvider cred = StaticCredentialsProvider.create(AwsSessionCredentials.create("ACCESSKEY", "SECRETKEY", "TOKENKEY"));
    localstack.start();
    snsBuilder = new SnsConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.SNS).toString()).setRegion(region).setCredentials(cred);
    sqsBuilder = new SqsConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.SQS).toString()).setRegion(region).setCredentials(cred);
    sqsService = new SqsService(sqsBuilder);
    s3Builder = new S3ConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.S3).toString()).setRegion(region).setCredentials(cred);
    dbBuilder = DynamoDbTestServices.getDynamoDbConnection(null);
    service = new DocumentServiceImpl(dbBuilder, "Documents");
    dbHelper = DynamoDbTestServices.getDynamoDbHelper(null);
    s3 = new S3Service(s3Builder);
    try (S3Client c = s3.buildClient()) {
        s3.createBucket(c, DOCUMENTS_BUCKET);
        s3.createBucket(c, STAGING_BUCKET);
    }
    if (!sqsService.exists(SNS_SQS_DELETE_QUEUE)) {
        snsSqsDeleteQueueUrl = sqsService.createQueue(SNS_SQS_DELETE_QUEUE).queueUrl();
    }
    if (!sqsService.exists(SNS_SQS_CREATE_QUEUE)) {
        snsSqsCreateQueueUrl = sqsService.createQueue(SNS_SQS_CREATE_QUEUE).queueUrl();
    }
    if (!sqsService.exists(ERROR_SQS_QUEUE)) {
        sqsErrorUrl = sqsService.createQueue(ERROR_SQS_QUEUE).queueUrl();
    }
    snsService = new SnsService(snsBuilder);
    snsDeleteTopic = snsService.createTopic("deleteDocument").topicArn();
    snsService.subscribe(snsDeleteTopic, "sqs", "arn:aws:sqs:us-east-1:000000000000:" + SNS_SQS_DELETE_QUEUE);
    snsCreateTopic = snsService.createTopic("createDocument").topicArn();
    snsService.subscribe(snsCreateTopic, "sqs", "arn:aws:sqs:us-east-1:000000000000:" + SNS_SQS_CREATE_QUEUE);
    if (!dbHelper.isDocumentsTableExists()) {
        dbHelper.createDocumentsTable();
        dbHelper.createCacheTable();
    }
}
Also used : DocumentServiceImpl(com.formkiq.stacks.dynamodb.DocumentServiceImpl) SqsConnectionBuilder(com.formkiq.aws.sqs.SqsConnectionBuilder) SnsService(com.formkiq.aws.sns.SnsService) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) SqsService(com.formkiq.aws.sqs.SqsService) S3ConnectionBuilder(com.formkiq.aws.s3.S3ConnectionBuilder) Region(software.amazon.awssdk.regions.Region) SnsConnectionBuilder(com.formkiq.aws.sns.SnsConnectionBuilder) S3Client(software.amazon.awssdk.services.s3.S3Client) S3Service(com.formkiq.aws.s3.S3Service) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with S3Service

use of com.formkiq.aws.s3.S3Service in project formkiq-core by formkiq.

the class LocalStackExtension method beforeAll.

@Override
public void beforeAll(final ExtensionContext context) throws Exception {
    this.localstack = TestServices.getLocalStack();
    this.localstack.start();
    S3Service s3service = new S3Service(TestServices.getS3Connection());
    try (S3Client s3 = s3service.buildClient()) {
        if (!s3service.exists(s3, BUCKET_NAME)) {
            s3service.createBucket(s3, BUCKET_NAME);
        }
        if (!s3service.exists(s3, STAGE_BUCKET_NAME)) {
            s3service.createBucket(s3, STAGE_BUCKET_NAME);
        }
    }
    new SsmServiceImpl(TestServices.getSsmConnection()).putParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/version", "1.1");
}
Also used : SsmServiceImpl(com.formkiq.aws.ssm.SsmServiceImpl) S3Client(software.amazon.awssdk.services.s3.S3Client) S3Service(com.formkiq.aws.s3.S3Service)

Example 3 with S3Service

use of com.formkiq.aws.s3.S3Service in project formkiq-core by formkiq.

the class ConsoleInstallHandlerTest method beforeClass.

/**
 * Before Class.
 *
 * @throws IOException IOException
 * @throws InterruptedException InterruptedException
 * @throws URISyntaxException URISyntaxException
 */
@BeforeClass
public static void beforeClass() throws IOException, URISyntaxException, InterruptedException {
    AwsCredentialsProvider cred = StaticCredentialsProvider.create(AwsSessionCredentials.create("ACCESSKEY", "SECRETKEY", "TOKENKEY"));
    localstack.start();
    s3Connection = new S3ConnectionBuilder().setCredentials(cred).setRegion(Region.US_EAST_1).setEndpointOverride(localstack.getEndpointOverride(Service.S3).toString());
    s3 = new S3Service(s3Connection);
    try (S3Client s = s3.buildClient()) {
        s3.createBucket(s, "distrobucket");
        s3.createBucket(s, "destbucket");
        try (InputStream is = LambdaContextRecorder.class.getResourceAsStream("/test.zip")) {
            s3.putObject(s, "distrobucket", "formkiq-console/0.1/formkiq-console.zip", is, null);
        }
    }
    connection = new HttpUrlConnectionRecorder(new URL("http://localhost"));
}
Also used : InputStream(java.io.InputStream) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) S3ConnectionBuilder(com.formkiq.aws.s3.S3ConnectionBuilder) S3Client(software.amazon.awssdk.services.s3.S3Client) S3Service(com.formkiq.aws.s3.S3Service) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 4 with S3Service

use of com.formkiq.aws.s3.S3Service in project formkiq-core by formkiq.

the class AwsResourceTest method beforeClass.

/**
 * beforeclass.
 *
 * @throws IOException IOException
 */
@BeforeClass
public static void beforeClass() throws IOException {
    Region region = Region.of(System.getProperty("testregion"));
    String awsprofile = System.getProperty("testprofile");
    appenvironment = System.getProperty("testappenvironment");
    final SsmConnectionBuilder ssmBuilder = new SsmConnectionBuilder().setCredentials(awsprofile).setRegion(region);
    ssmService = new SsmServiceImpl(ssmBuilder);
    final S3ConnectionBuilder s3Builder = new S3ConnectionBuilder().setCredentials(awsprofile).setRegion(region);
    s3 = new S3Service(s3Builder);
}
Also used : SsmServiceImpl(com.formkiq.aws.ssm.SsmServiceImpl) SsmConnectionBuilder(com.formkiq.aws.ssm.SsmConnectionBuilder) S3ConnectionBuilder(com.formkiq.aws.s3.S3ConnectionBuilder) Region(software.amazon.awssdk.regions.Region) S3Service(com.formkiq.aws.s3.S3Service) BeforeClass(org.junit.BeforeClass)

Example 5 with S3Service

use of com.formkiq.aws.s3.S3Service in project formkiq-core by formkiq.

the class DocumentIdRequestHandler method delete.

@Override
public ApiRequestHandlerResponse delete(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
    String documentBucket = awsservice.documents3bucket();
    String documentId = event.getPathParameters().get("documentId");
    logger.log("deleting object " + documentId + " from bucket '" + documentBucket + "'");
    try {
        S3Service s3Service = awsservice.s3Service();
        try (S3Client s3 = s3Service.buildClient()) {
            S3ObjectMetadata md = s3Service.getObjectMetadata(s3, documentBucket, documentId);
            if (md.isObjectExists()) {
                s3Service.deleteObject(s3, documentBucket, documentId);
                ApiResponse resp = new ApiMessageResponse("'" + documentId + "' object deleted");
                return new ApiRequestHandlerResponse(SC_OK, resp);
            }
        }
        throw new NotFoundException("Document " + documentId + " not found.");
    } catch (S3Exception e) {
        if (e.statusCode() == SC_NOT_FOUND.getStatusCode()) {
            throw new NotFoundException("Document " + documentId + " not found.");
        }
        throw e;
    }
}
Also used : ApiMessageResponse(com.formkiq.lambda.apigateway.ApiMessageResponse) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) NotFoundException(com.formkiq.lambda.apigateway.exception.NotFoundException) S3ObjectMetadata(com.formkiq.aws.s3.S3ObjectMetadata) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) S3Client(software.amazon.awssdk.services.s3.S3Client) S3Service(com.formkiq.aws.s3.S3Service) ApiResponse(com.formkiq.lambda.apigateway.ApiResponse)

Aggregations

S3Service (com.formkiq.aws.s3.S3Service)11 S3Client (software.amazon.awssdk.services.s3.S3Client)8 S3ConnectionBuilder (com.formkiq.aws.s3.S3ConnectionBuilder)6 SnsConnectionBuilder (com.formkiq.aws.sns.SnsConnectionBuilder)4 SnsService (com.formkiq.aws.sns.SnsService)4 SqsConnectionBuilder (com.formkiq.aws.sqs.SqsConnectionBuilder)4 SqsService (com.formkiq.aws.sqs.SqsService)4 SsmServiceImpl (com.formkiq.aws.ssm.SsmServiceImpl)4 BeforeClass (org.junit.BeforeClass)4 Region (software.amazon.awssdk.regions.Region)4 SsmConnectionBuilder (com.formkiq.aws.ssm.SsmConnectionBuilder)3 DocumentServiceImpl (com.formkiq.stacks.dynamodb.DocumentServiceImpl)3 AwsCredentialsProvider (software.amazon.awssdk.auth.credentials.AwsCredentialsProvider)3 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)2 ArtifactStoreService (ai.verta.modeldb.artifactStore.storageservice.ArtifactStoreService)1 NFSService (ai.verta.modeldb.artifactStore.storageservice.nfs.NFSService)1 S3Service (ai.verta.modeldb.artifactStore.storageservice.s3.S3Service)1 ModelDBException (ai.verta.modeldb.common.exceptions.ModelDBException)1 LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)1 S3ObjectMetadata (com.formkiq.aws.s3.S3ObjectMetadata)1