Skip to content

Commit

Permalink
Merge pull request #87 from kookmin-sw/jmpark
Browse files Browse the repository at this point in the history
Lambda 환경변수 적용 및 Log API 구현
  • Loading branch information
mh3ong authored May 19, 2024
2 parents 071d38a + 739a58e commit e37d657
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 64 deletions.
9 changes: 5 additions & 4 deletions backend/sskai-ddb-data-api/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import {
import { DeleteObjectCommand, DeleteObjectsCommand, S3Client } from "@aws-sdk/client-s3";
import { randomUUID } from 'crypto';

const client = new DynamoDBClient({});
const clientS3 = new S3Client({});
const region = process.env.AWS_REGION;
const client = new DynamoDBClient({ region });
const clientS3 = new S3Client({ region });
const dynamo = DynamoDBDocumentClient.from(client);
const TableName = "sskai-data";
const Bucket = "sskai-model-storage";
const Bucket = process.env.BUCKET_NAME;
const REQUIRED_FIELDS = ["name", "user"];

export const handler = async (event) => {
Expand Down Expand Up @@ -137,7 +138,7 @@ export const handler = async (event) => {
await clientS3.send(deleteFileCommand);
await clientS3.send(deletedDirCommand);

body = { message: "Data deleted", uid: event.pathParameters.id };
body = { message: "Data deleted", uid: event.pathParameters.id, data: deleted.Attributes};
break;
}
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion backend/sskai-ddb-inferences-api/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
} from "@aws-sdk/lib-dynamodb";
import { randomUUID } from 'crypto';

const client = new DynamoDBClient({});
const region = process.env.AWS_REGION;
const client = new DynamoDBClient({ region });
const dynamo = DynamoDBDocumentClient.from(client);
const TableName = "sskai-inferences";
const REQUIRED_FIELDS = ["name", "model", "type"];
Expand Down
21 changes: 11 additions & 10 deletions backend/sskai-ddb-logs-api/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import {
DynamoDBDocumentClient,
PutCommand,
ScanCommand,
QueryCommand,
} from "@aws-sdk/lib-dynamodb";
import { randomUUID } from 'crypto';

const client = new DynamoDBClient({});
const region = process.env.AWS_REGION;
const client = new DynamoDBClient({ region });
const dynamo = DynamoDBDocumentClient.from(client);
const TableName = "sskai-logs"

Expand All @@ -28,26 +29,26 @@ export const handler = async (event) => {
user: data.user,
kind_of_job: data.kind_of_job,
job: data.job,
type: data.type,
name: data.name,
created_at: new Date().getTime(),
}
};
await dynamo.send(new PutCommand(command));
body = { message: "Log created", log: command };
break;

case "GET /logs/{id}":
command = {
case "GET /logs":
body = await dynamo.send(new QueryCommand({
TableName,
FilterExpression: '#user = :user',
IndexName: "user-index",
KeyConditionExpression: "#user = :user",
ExpressionAttributeNames: {
"#user": "user"
},
ExpressionAttributeValues: {
':user': event.pathParameters.id,
}
};
body = await dynamo.send(new ScanCommand(command));
':user': event.headers.user,
},
}));
body = body.Items;
break;
}
Expand Down
9 changes: 5 additions & 4 deletions backend/sskai-ddb-models-api/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import {
import { DeleteObjectCommand, DeleteObjectsCommand, S3Client } from "@aws-sdk/client-s3";
import { randomUUID } from 'crypto';

const client = new DynamoDBClient({});
const clientS3 = new S3Client({});
const region = process.env.AWS_REGION;
const client = new DynamoDBClient({ region });
const clientS3 = new S3Client({ region });
const dynamo = DynamoDBDocumentClient.from(client);
const TableName = "sskai-models";
const Bucket = "sskai-model-storage";
const Bucket = process.env.BUCKET_NAME;
const REQUIRED_FIELDS = ["name", "type", "user"];

export const handler = async (event) => {
Expand Down Expand Up @@ -150,7 +151,7 @@ export const handler = async (event) => {
await clientS3.send(deleteFileCommand);
await clientS3.send(deletedDirCommand);

body = { message: "Model deleted", uid: event.pathParameters.id };
body = { message: "Model deleted", uid: event.pathParameters.id, model: deleted.Attributes };
break;
}
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion backend/sskai-ddb-trains-api/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
} from "@aws-sdk/lib-dynamodb";
import { randomUUID } from 'crypto';

const client = new DynamoDBClient({});
const region = process.env.AWS_REGION;
const client = new DynamoDBClient({ region });
const dynamo = DynamoDBDocumentClient.from(client);
const TableName = "sskai-trains";
const REQUIRED_FIELDS = ["name", "data", "user"];
Expand Down
3 changes: 2 additions & 1 deletion backend/sskai-ddb-users-api/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
} from "@aws-sdk/lib-dynamodb";
import { randomUUID } from 'crypto';

const client = new DynamoDBClient({});
const region = process.env.AWS_REGION;
const client = new DynamoDBClient({ region });
const dynamo = DynamoDBDocumentClient.from(client);
const TableName = "sskai-users"
const REQUIRED_FIELDS = ["email", "name"];
Expand Down
5 changes: 3 additions & 2 deletions backend/sskai-s3-multipart-presigned-url/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
} from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";

const Bucket = 'sskai-model-storage';
const client = new S3Client({ region: 'ap-northeast-2' });
const region = process.env.AWS_REGION;
const Bucket = process.env.BUCKET_NAME;
const client = new S3Client({ region });

export const handler = async (event) => {
let body, statusCode = 200;
Expand Down
7 changes: 5 additions & 2 deletions backend/sskai-s3-presigned-url-api/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";

const region = process.env.AWS_REGION;
const Bucket = process.env.BUCKET_NAME;
const client = new S3Client({ region });

export const handler = async (event) => {
const headers = {
'Content-Type': "application/json"
Expand Down Expand Up @@ -37,8 +41,7 @@ export const handler = async (event) => {
headers
};

const client = new S3Client({ region: 'ap-northeast-2' });
const command = new PutObjectCommand({ Bucket: 'sskai-model-storage', Key: `${user_uid}/${upload_type}/${uid}/${upload_type}.zip` });
const command = new PutObjectCommand({ Bucket, Key: `${user_uid}/${upload_type}/${uid}/${upload_type}.zip` });
const url = await getSignedUrl(client, command, { expiresIn: 3600 });

return {
Expand Down
Loading

0 comments on commit e37d657

Please sign in to comment.