Skip to content

Commit

Permalink
updates contact loader csv s3 upload sign up to v3 of aws-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Arique1104 committed Dec 1, 2023
1 parent 8dd0e13 commit ec8296c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/extensions/contact-loaders/csv-s3-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { unzipPayload } from "../../../workers/jobs";
import { getConfig, hasConfig } from "../../../server/api/lib/config";
import { gunzip } from "../../../lib";

import AWS from "aws-sdk";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { PutObjectCommand, S3 } from "@aws-sdk/client-s3";

export const name = "csv-s3-upload";

Expand Down Expand Up @@ -67,8 +68,11 @@ export async function getClientChoiceData(
/// The react-component will be sent this data as a property
/// return a json object which will be cached for expiresSeconds long
/// `data` should be a single string -- it can be JSON which you can parse in the client component
const s3 = new AWS.S3({
const s3 = new S3({
// The key signatureVersion is no longer supported in v3, and can be removed.
// @deprecated SDK v3 only supports signature v4.
signatureVersion: "v4",

region: getConfig("AWS_REGION")
});
const key = `contacts-upload/${campaign.id}/contacts.json.gz`;
Expand All @@ -80,7 +84,9 @@ export async function getClientChoiceData(
Expires: 1800 // 30 minutes
};

const result = await s3.getSignedUrl("putObject", params);
const result = await await getSignedUrl(s3, new PutObjectCommand(params), {
expiresIn: "/* add value from 'Expires' from v2 call if present, else remove */"
});

return {
data: JSON.stringify({ s3Url: result, s3key: key }),
Expand Down Expand Up @@ -116,16 +122,19 @@ export async function processContactLoad(job, maxContacts, organization) {
/// * Batching
/// * Error handling
/// * "Request of Doom" scenarios -- queries or jobs too big to complete
const s3 = new AWS.S3({
const s3 = new S3({
// The key signatureVersion is no longer supported in v3, and can be removed.
// @deprecated SDK v3 only supports signature v4.
signatureVersion: "v4",

region: getConfig("AWS_REGION")
});
var params = {
Bucket: getConfig("AWS_S3_BUCKET_NAME"),
Key: job.payload
};

const contactsData = (await s3.getObject(params).promise()).Body.toString(
const contactsData = (await s3.getObject(params)).Body.toString(
"utf-8"
);
const parsedData = JSON.parse(
Expand Down

0 comments on commit ec8296c

Please sign in to comment.