Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump @aws-sdk/client-s3 from 3.226.0 to 3.592.0 in /app #3348

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app/backend/lib/awsCommon.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import http from 'https';
import { NodeHttpHandler } from '@aws-sdk/node-http-handler';
import { NodeHttpHandler } from '@smithy/node-http-handler';
import {
fromTemporaryCredentials,
fromEnv,
} from '@aws-sdk/credential-providers';
import { S3ClientConfig } from '@aws-sdk/client-s3';
import { SNSClientConfig } from '@aws-sdk/client-sns';
import config from '../../config';
import CustomHttpsAgent from './CustomHttpsAgent';

Expand All @@ -24,7 +25,7 @@ const nodeHandler = new NodeHttpHandler({
connectionTimeout: 30000,
});

const awsConfig: S3ClientConfig = {
const awsConfig: any = {
region: AWS_S3_REGION,
logger: ENABLE_AWS_LOGS && console,
requestHandler: nodeHandler,
Expand All @@ -40,4 +41,10 @@ const awsConfig: S3ClientConfig = {
}),
};

export default awsConfig;
export const awsS3Config: S3ClientConfig = {
...awsConfig,
};

export const awsSNSConfig: SNSClientConfig = {
...awsConfig,
};
53 changes: 29 additions & 24 deletions app/backend/lib/s3client.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { S3Client, GetObjectCommand, GetObjectTaggingCommand, HeadObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
import {
S3Client,
GetObjectCommand,
GetObjectTaggingCommand,
HeadObjectCommand,
PutObjectCommand,
} from '@aws-sdk/client-s3';

import config from '../../config/index';
import awsConfig from './awsCommon'
import { awsS3Config } from './awsCommon';

const AWS_S3_BUCKET = config.get('AWS_S3_BUCKET');

const s3ClientV3sdk = new S3Client(awsConfig);
const s3ClientV3sdk = new S3Client(awsS3Config);

export const getSignedUrlPromise = async(params) => {
export const getSignedUrlPromise = async (params) => {
const command = new GetObjectCommand(params);
return getSignedUrl(s3ClientV3sdk, command, { expiresIn: 3600 });
}
};

export const getFileFromS3 = async (uuid, filename, res) => {
const params = {
Expand All @@ -30,37 +36,36 @@ export const getFileFromS3 = async (uuid, filename, res) => {
.catch(() => {
res.status(500).end();
});
}
};

export const checkFileExists = async (params) =>{
try {
export const checkFileExists = async (params) => {
try {
const command = new HeadObjectCommand(params);
const response = await s3ClientV3sdk.send(command);
if (response.$metadata?.httpStatusCode !== 200) return false;
const response = await s3ClientV3sdk.send(command);
if (response.$metadata?.httpStatusCode !== 200) return false;
} catch (error) {
return false;
}
return true;
}
};

export const getFileTagging = async (params) =>{
const noData={TagSet:[]};
try {
export const getFileTagging = async (params) => {
const noData = { TagSet: [] };
try {
const command = new GetObjectTaggingCommand(params);
const response = await s3ClientV3sdk.send(command);
if (response.$metadata?.httpStatusCode !== 200) return noData;
return response;
const response = await s3ClientV3sdk.send(command);
if (response.$metadata?.httpStatusCode !== 200) return noData;
return response;
} catch (error) {
return noData;
}
}
};

export const uploadFileToS3 = async(params) =>
{
const command = new PutObjectCommand(params);
const response = await s3ClientV3sdk.send(command);
if (response.$metadata?.httpStatusCode !== 200) return false;
export const uploadFileToS3 = async (params) => {
const command = new PutObjectCommand(params);
const response = await s3ClientV3sdk.send(command);
if (response.$metadata?.httpStatusCode !== 200) return false;
return true;
}
};

export const s3ClientV3 = s3ClientV3sdk;
19 changes: 11 additions & 8 deletions app/backend/lib/sns-client.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { SNSClient, PublishCommand } from "@aws-sdk/client-sns";
import { SNSClient, PublishCommand } from '@aws-sdk/client-sns';

import awsConfig from './awsCommon'
import { awsSNSConfig } from './awsCommon';

export const snsClient = new SNSClient(awsConfig);
export const snsClient = new SNSClient(awsSNSConfig);

export const pushMessage = async (topic:string, uuid: string, body: string) => {
export const pushMessage = async (
topic: string,
uuid: string,
body: string
) => {
const params = {
Message: body,
Subject: uuid,
TopicArn: topic
TopicArn: topic,
};

const response = {result:''};
const response = { result: '' };
try {
await snsClient.send(new PublishCommand(params));
response.result = 'Success';
} catch (e) {
} catch (e) {
response.result = `Error ${e.stack}`;
}
return Promise.resolve(response);
};

5 changes: 3 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"format": "prettier --write './**/*.tsx' --config ../.prettierrc"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.226.0",
"@aws-sdk/client-s3": "^3.592.0",
"@aws-sdk/client-sns": "^3.245.0",
"@aws-sdk/credential-providers": "^3.515.0",
"@aws-sdk/lib-storage": "^3.226.0",
Expand Down Expand Up @@ -103,6 +103,7 @@
"react-typography": "^0.16.23",
"relay-nextjs": "^0.8.0",
"relay-runtime": "^13.2.0",
"@smithy/node-http-handler": "^3.0.0",
"styled-components": "^5.3.5",
"typography": "^0.16.21",
"url": "^0.11.3",
Expand All @@ -111,7 +112,7 @@
"xlsx": "https://cdn.sheetjs.com/xlsx-0.19.3/xlsx-0.19.3.tgz"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.226.0",
"@aws-sdk/client-s3": "^3.592.0",
"@microsoft/eslint-formatter-sarif": "^3.0.0",
"@testing-library/cypress": "^10.0.1",
"@testing-library/jest-dom": "^6.4.5",
Expand Down
Loading
Loading