Search in sources :

Example 1 with AwsServiceException

use of software.amazon.awssdk.awscore.exception.AwsServiceException in project flyway by flyway.

the class AwsS3Resource method read.

@Override
public Reader read() {
    S3Client s3 = S3ClientFactory.getClient();
    try {
        GetObjectRequest.Builder builder = GetObjectRequest.builder().bucket(bucketName).key(s3ObjectSummary.key());
        GetObjectRequest request = builder.build();
        ResponseInputStream o = s3.getObject(request);
        return Channels.newReader(Channels.newChannel(o), encoding.name());
    } catch (AwsServiceException e) {
        LOG.error(e.getMessage(), e);
        throw new FlywayException("Failed to get object from s3: " + e.getMessage(), e);
    }
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) S3Client(software.amazon.awssdk.services.s3.S3Client) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest)

Example 2 with AwsServiceException

use of software.amazon.awssdk.awscore.exception.AwsServiceException in project aws-doc-sdk-examples by awsdocs.

the class DeleteIdentityPool method deleteIdPool.

// snippet-start:[cognito.java2.deleteidpool.main]
public static void deleteIdPool(CognitoIdentityClient cognitoIdClient, String identityPoold) {
    try {
        DeleteIdentityPoolRequest identityPoolRequest = DeleteIdentityPoolRequest.builder().identityPoolId(identityPoold).build();
        cognitoIdClient.deleteIdentityPool(identityPoolRequest);
        System.out.println("Done");
    } catch (AwsServiceException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DeleteIdentityPoolRequest(software.amazon.awssdk.services.cognitoidentity.model.DeleteIdentityPoolRequest) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException)

Example 3 with AwsServiceException

use of software.amazon.awssdk.awscore.exception.AwsServiceException in project aws-doc-sdk-examples by awsdocs.

the class AmazonPersonalizeRecommender method putEvent.

public void putEvent(UserEvent e) {
    try {
        Event event = Event.builder().eventId(UUID.randomUUID().toString()).eventType(e.event).itemId(e.itemId).sentAt(Instant.ofEpochMilli(System.currentTimeMillis() + 10 * 60 * 1000)).build();
        PutEventsRequest putEventsRequest = PutEventsRequest.builder().trackingId(trackingId).userId(e.getUserId()).sessionId("temp").eventList(event).build();
        personalizeEventsClient.putEvents(putEventsRequest);
        System.out.println("Event sent: " + e);
    } catch (AwsServiceException ex) {
        System.err.println(ex.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) Event(software.amazon.awssdk.services.personalizeevents.model.Event) PutEventsRequest(software.amazon.awssdk.services.personalizeevents.model.PutEventsRequest)

Example 4 with AwsServiceException

use of software.amazon.awssdk.awscore.exception.AwsServiceException in project aws-doc-sdk-examples by awsdocs.

the class AmazonPersonalizeRecommender method getItemsForUser.

public List<Item> getItemsForUser(String userId) {
    List<Item> list = new ArrayList<>();
    try {
        GetRecommendationsRequest recommendationsRequest = GetRecommendationsRequest.builder().campaignArn(userPersonalizationCampaignArn).numResults(20).userId(userId).build();
        GetRecommendationsResponse recommendationsResponse = personalizeRuntimeClient.getRecommendations(recommendationsRequest);
        List<PredictedItem> items = recommendationsResponse.itemList();
        for (PredictedItem item : items) {
            list.add(new Item(item.itemId(), itemIdToNameMap.get(item.itemId())));
        }
    } catch (AwsServiceException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return list;
}
Also used : PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) GetRecommendationsRequest(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest) PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) ArrayList(java.util.ArrayList) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) GetRecommendationsResponse(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsResponse)

Example 5 with AwsServiceException

use of software.amazon.awssdk.awscore.exception.AwsServiceException in project aws-doc-sdk-examples by awsdocs.

the class AmazonPersonalizeRecommender method getItemsForItem.

public List<Item> getItemsForItem(String itemId) {
    List<Item> list = new ArrayList<>();
    try {
        GetRecommendationsRequest simsRequest = GetRecommendationsRequest.builder().campaignArn(simsCampaignArn).itemId(itemId).build();
        GetRecommendationsResponse simsResponse = personalizeRuntimeClient.getRecommendations(simsRequest);
        List<PredictedItem> items = simsResponse.itemList();
        for (PredictedItem item : items) {
            list.add(new Item(item.itemId(), itemIdToNameMap.get(item.itemId())));
        }
    } catch (AwsServiceException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return list;
}
Also used : PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) GetRecommendationsRequest(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest) PredictedItem(software.amazon.awssdk.services.personalizeruntime.model.PredictedItem) ArrayList(java.util.ArrayList) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) GetRecommendationsResponse(software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsResponse)

Aggregations

AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)8 GetRecommendationsRequest (software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsRequest)3 GetRecommendationsResponse (software.amazon.awssdk.services.personalizeruntime.model.GetRecommendationsResponse)3 PredictedItem (software.amazon.awssdk.services.personalizeruntime.model.PredictedItem)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 SdkClientException (software.amazon.awssdk.core.exception.SdkClientException)2 FlywayException (org.flywaydb.core.api.FlywayException)1 ResponseInputStream (software.amazon.awssdk.core.ResponseInputStream)1 DeleteIdentityPoolRequest (software.amazon.awssdk.services.cognitoidentity.model.DeleteIdentityPoolRequest)1 Event (software.amazon.awssdk.services.personalizeevents.model.Event)1 PutEventsRequest (software.amazon.awssdk.services.personalizeevents.model.PutEventsRequest)1 S3Client (software.amazon.awssdk.services.s3.S3Client)1 Bucket (software.amazon.awssdk.services.s3.model.Bucket)1 BucketAlreadyExistsException (software.amazon.awssdk.services.s3.model.BucketAlreadyExistsException)1 BucketAlreadyOwnedByYouException (software.amazon.awssdk.services.s3.model.BucketAlreadyOwnedByYouException)1 CreateBucketConfiguration (software.amazon.awssdk.services.s3.model.CreateBucketConfiguration)1 CreateBucketRequest (software.amazon.awssdk.services.s3.model.CreateBucketRequest)1 GetObjectRequest (software.amazon.awssdk.services.s3.model.GetObjectRequest)1 PutObjectRequest (software.amazon.awssdk.services.s3.model.PutObjectRequest)1