Skip to content

Commit

Permalink
fix: naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Generalov authored and Evgeny Generalov committed Nov 15, 2020
1 parent ebe8185 commit dea1b6a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/import-service/.env
@@ -1,4 +1,4 @@
IMPORT_S3_BUCKET=nodejs-aws-task5-csv
IMPORT_S3_PREFIX=uploaded/
IMPORT_S3_REGION=us-east-2
PARSED_S3_PREFIX=parsed/
IMPORT_S3_PARSED_PREFIX=parsed/
IMPORT_S3_UPLOAD_PREFIX=uploaded/
2 changes: 1 addition & 1 deletion packages/import-service/serverless.yml
Expand Up @@ -58,5 +58,5 @@ functions:
bucket: "${env:IMPORT_S3_BUCKET}"
event: "s3:ObjectCreated:*"
rules:
- prefix: "${env:IMPORT_S3_PREFIX}"
- prefix: "${env:IMPORT_S3_UPLOAD_PREFIX}"
existing: true
9 changes: 6 additions & 3 deletions packages/import-service/src/handlers/importFileParser.js
Expand Up @@ -9,9 +9,9 @@ const pipeline = promisify(_pipeline);

const {
IMPORT_S3_BUCKET,
IMPORT_S3_PREFIX,
IMPORT_S3_UPLOAD_PREFIX,
IMPORT_S3_REGION,
PARSED_S3_PREFIX,
IMPORT_S3_PARSED_PREFIX,
} = process.env;

export const handler = middy(importFileParser).use([middyRequestLogger()]);
Expand All @@ -21,7 +21,10 @@ export async function importFileParser(event, context, callback) {

const tasks = event.Records.map(async (record) => {
const srcKey = record.s3.object.key;
const destKey = srcKey.replace(IMPORT_S3_PREFIX, PARSED_S3_PREFIX);
const destKey = srcKey.replace(
IMPORT_S3_UPLOAD_PREFIX,
IMPORT_S3_PARSED_PREFIX
);

// parse CSV
const uploadedObject = s3.getObject({
Expand Down
8 changes: 6 additions & 2 deletions packages/import-service/src/handlers/importProductsFile.js
Expand Up @@ -5,7 +5,11 @@ import middyHttpCors from "@middy/http-cors";
import middyErrorHandler from "middy-error-handler";
import middyRequestLogger from "middy-request-logger";

const { IMPORT_S3_BUCKET, IMPORT_S3_PREFIX, IMPORT_S3_REGION } = process.env;
const {
IMPORT_S3_BUCKET,
IMPORT_S3_UPLOAD_PREFIX,
IMPORT_S3_REGION,
} = process.env;
const ALLOWED_CONTENT_TYPES = [
"text/csv",
"application/vnd.ms-excel",
Expand All @@ -29,7 +33,7 @@ export async function importProductsFile(event, context, callback) {
}

const s3 = new AWS.S3({ region: IMPORT_S3_REGION });
const uploadPath = [IMPORT_S3_PREFIX, fileName].join("");
const uploadPath = IMPORT_S3_UPLOAD_PREFIX + fileName;
const url = await s3.getSignedUrlPromise("putObject", {
Bucket: IMPORT_S3_BUCKET,
Key: uploadPath,
Expand Down

0 comments on commit dea1b6a

Please sign in to comment.