use of com.amazonaws.athena.connector.lambda.security.BlockCrypto in project aws-athena-query-federation by awslabs.
the class S3BlockSpillReader method read.
/**
* Reads a spilled block.
*
* @param spillLocation The location to read the spilled Block from.
* @param key The encryption key to use when reading the spilled Block.
* @param schema The Schema to use when deserializing the spilled Block.
* @return The Block stored at the spill location.
*/
public Block read(S3SpillLocation spillLocation, EncryptionKey key, Schema schema) {
S3Object fullObject = null;
try {
logger.debug("read: Started reading block from S3");
fullObject = amazonS3.getObject(spillLocation.getBucket(), spillLocation.getKey());
logger.debug("read: Completed reading block from S3");
BlockCrypto blockCrypto = (key != null) ? new AesGcmBlockCrypto(allocator) : new NoOpBlockCrypto(allocator);
Block block = blockCrypto.decrypt(key, ByteStreams.toByteArray(fullObject.getObjectContent()), schema);
logger.debug("read: Completed decrypting block of size.");
return block;
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
if (fullObject != null) {
try {
fullObject.close();
} catch (IOException ex) {
logger.warn("read: Exception while closing S3 object", ex);
}
}
}
}
use of com.amazonaws.athena.connector.lambda.security.BlockCrypto in project aws-athena-query-federation by awslabs.
the class S3BlockSpillReader method read.
/**
* Reads spilled data as a byte[].
*
* @param spillLocation The location to read the spilled Block from.
* @param key The encryption key to use when reading the spilled Block.
* @return The Block stored at the spill location.
*/
public byte[] read(S3SpillLocation spillLocation, EncryptionKey key) {
S3Object fullObject = null;
try {
logger.debug("read: Started reading block from S3");
fullObject = amazonS3.getObject(spillLocation.getBucket(), spillLocation.getKey());
logger.debug("read: Completed reading block from S3");
BlockCrypto blockCrypto = (key != null) ? new AesGcmBlockCrypto(allocator) : new NoOpBlockCrypto(allocator);
return blockCrypto.decrypt(key, ByteStreams.toByteArray(fullObject.getObjectContent()));
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
if (fullObject != null) {
try {
fullObject.close();
} catch (IOException ex) {
logger.warn("read: Exception while closing S3 object", ex);
}
}
}
}
Aggregations