Skip to content

Commit 7e6e42a

Browse files
committed
update to aws sdk v3/ node 18
1 parent bac6e28 commit 7e6e42a

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this
44
software and associated documentation files (the "Software"), to deal in the Software
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: MIT-0
3-
const util = require('./util');
3+
import { runQuery } from './util.mjs'
44

55
// AWS Glue Data Catalog database and table
66
const table = process.env.TABLE;
77
const database = process.env.DATABASE;
88

99
// creates partitions for the hour after the current hour
10-
exports.handler = async (event, context, callback) => {
10+
export const handler = async () => {
1111
const nextHour = new Date(Date.now() + 60 * 60 * 1000);
1212
const year = nextHour.getUTCFullYear();
1313
const month = (nextHour.getUTCMonth() + 1).toString().padStart(2, '0');
@@ -24,5 +24,5 @@ exports.handler = async (event, context, callback) => {
2424
day = '${day}',
2525
hour = '${hour}' );`;
2626

27-
await util.runQuery(createPartitionStatement);
27+
await runQuery(createPartitionStatement);
2828
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: MIT-0
3-
const aws = require('aws-sdk');
4-
const s3 = new aws.S3({ apiVersion: '2006-03-01' });
3+
import { S3Client } from "@aws-sdk/client-s3";
4+
import { CopyObjectCommand } from '@aws-sdk/client-s3';
5+
import { DeleteObjectCommand } from '@aws-sdk/client-s3';
6+
const s3 = new S3Client();
57

68
// prefix to copy partitioned data to w/o leading but w/ trailing slash
79
const targetKeyPrefix = process.env.TARGET_KEY_PREFIX;
@@ -14,7 +16,7 @@ const targetKeyPrefix = process.env.TARGET_KEY_PREFIX;
1416
const datePattern = '[^\\d](\\d{4})-(\\d{2})-(\\d{2})-(\\d{2})[^\\d]';
1517
const filenamePattern = '[^/]+$';
1618

17-
exports.handler = async (event, context, callback) => {
19+
export const handler = async (event, _, callback) => {
1820
const moves = event.Records.map(record => {
1921
const bucket = record.s3.bucket.name;
2022
const sourceKey = record.s3.object.key;
@@ -37,13 +39,13 @@ exports.handler = async (event, context, callback) => {
3739
Bucket: bucket,
3840
Key: targetKey
3941
};
40-
const copy = s3.copyObject(copyParams).promise();
42+
const copy = s3.send(new CopyObjectCommand(copyParams));
4143

4244
const deleteParams = { Bucket: bucket, Key: sourceKey };
4345

4446
return copy.then(function () {
4547
console.log(`Copied. Now deleting ${sourceKey}.`);
46-
const del = s3.deleteObject(deleteParams).promise();
48+
const del = s3.send(new DeleteObjectCommand(deleteParams));
4749
console.log(`Deleted ${sourceKey}.`);
4850
return del;
4951
}, function (reason) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: MIT-0
3-
const util = require('./util');
3+
import { runQuery } from './util.mjs'
44

55
// AWS Glue Data Catalog database and tables
66
const sourceTable = process.env.SOURCE_TABLE;
77
const targetTable = process.env.TARGET_TABLE;
88
const database = process.env.DATABASE;
99

1010
// get the partition of 2hours ago
11-
exports.handler = async (event, context, callback) => {
11+
export const handler = async () => {
1212
const partitionHour = new Date(Date.now() - 120 * 60 * 1000);
1313
const year = partitionHour.getUTCFullYear();
1414
const month = (partitionHour.getUTCMonth() + 1).toString().padStart(2, '0');
@@ -26,5 +26,5 @@ exports.handler = async (event, context, callback) => {
2626
AND day = '${day}'
2727
AND hour = '${hour}';`;
2828

29-
await util.runQuery(ctasStatement);
29+
await runQuery(ctasStatement);
3030
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: MIT-0
3-
const aws = require('aws-sdk');
4-
const athena = new aws.Athena({ apiVersion: '2017-05-18' });
3+
import { AthenaClient, GetQueryExecutionCommand, StartQueryExecutionCommand } from '@aws-sdk/client-athena';
4+
const athena = new AthenaClient();
55

66
// s3 URL of the query results (without trailing slash)
77
const athenaQueryResultsLocation = process.env.ATHENA_QUERY_RESULTS_LOCATION;
88

99
async function waitForQueryExecution(queryExecutionId) {
1010
while (true) {
11-
const data = await athena.getQueryExecution({
11+
const data = await athena.send(new GetQueryExecutionCommand({
1212
QueryExecutionId: queryExecutionId
13-
}).promise();
13+
}));
1414
const state = data.QueryExecution.Status.State;
1515
if (state === 'SUCCEEDED') {
1616
return;
@@ -21,13 +21,14 @@ async function waitForQueryExecution(queryExecutionId) {
2121
}
2222
}
2323

24-
exports.runQuery = async (query) => {
24+
25+
export function runQuery(query) {
2526
const params = {
2627
QueryString: query,
2728
ResultConfiguration: {
2829
OutputLocation: athenaQueryResultsLocation
2930
}
3031
};
31-
return athena.startQueryExecution(params).promise()
32+
return athena.send(new StartQueryExecutionCommand(params))
3233
.then(data => waitForQueryExecution(data.QueryExecutionId));
3334
}

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)