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

Task5 #4

Merged
merged 10 commits into from Nov 17, 2020
Merged

Task5 #4

merged 10 commits into from Nov 17, 2020

Conversation

generalov
Copy link
Owner

@generalov generalov commented Nov 14, 2020

Frontend: https://dibzgqdmk7fo5.cloudfront.net (task4 PR: generalov/nodejs-aws-fe#4)
Implemented Endpoints: https://app.swaggerhub.com/apis-docs/e.generalov/nodejs-aws/1.4

Prerequisites


TASK 5.1


  • Create a new service, called import-service, with a its own serverless.yml file at the same level as product service.
  • Create a lambda function in that serverless.yml file, called importProductsFile, which will be triggered by the HTTP GET method.
    • The requested URL should be /import.
    • The name of CSV file with products will be passed in a query string as a name parameter and should be described in the serverless.yml file as a request parameter.
    • A new Signed URL should be created with the following Key: uploaded/${fileName}.
    • The response from the lambda should be the created Signed URL.
  • Update serverless.yml with policies to allow lambda functions to interact with S3.
  • The lambda endpoint should be integrated with the frontend by updating import property of the API paths configuration.

TASK 5.2


  • Create a lambda function under the same serverless.yml file, called importFileParser, which will be triggered by the S3 s3:ObjectCreated:* event.
  • Configure the event to be triggered only by changes in the uploaded folder in S3.
  • The lambda function should use the Readable stream to get an object from S3, parse it via csv-parser and log each record to be shown in CloudWatch.
  • The response should be a correct HTTP response code.

Evaluation criteria


Reviewers should verify the lambda functions by invoking them through provided URLs.

  • 1 - File serverless.yml contains configuration for importProductsFile function
  • 3 - The importProductsFile lambda function returns a correct response which can be used to upload a file into the S3 bucket
  • 4 - Frontend application is integrated with importProductsFile lambda
  • 5 - The importFileParser lambda function is implemented and serverless.yml contains configuration for the lambda

Additional (optional) tasks


  • +1 - async/await is used in lambda functions
  • +1 - importProductsFile lambda is covered by unit tests (aws-sdk-mock can be used to mock S3 methods - https://www.npmjs.com/package/aws-sdk-mock)
    I've tried to write tests using aws-sdk-mock but it incorrectly mocks the method S3:getSignedUrlPromise() returning a callbackish response { promise, createReadStream, ... }. So Jest is being used.
  • +1 - At the end of the stream the lambda function should move the file from the uploaded folder into the parsed folder (move the file means that file should be copied into parsed folder, and then deleted from uploaded folder)

Copy link

@Vladlan Vladlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not working csv file upload:
generalov_error

Discord Vladlan #8201

@@ -1,4 +1,4 @@
IMPORT_S3_BUCKET=nodejs-aws-task5-csv
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even this constants could be exposed, better to not commit .env file to a repo

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They have a bit different rules:

Note: .env, .env.development, and .env.production files should be included in your repository as they define defaults. .env*.local should be added to .gitignore, as those files are intended to be ignored. .env.local is where secrets can be stored.

https://www.serverless.com/plugins/serverless-dotenv-plugin

So, I'm storing confidential data in .env.*.local files.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@generalov
Copy link
Owner Author

Not working csv file upload:
generalov_error

Discord Vladlan #8201

@Vladlan Sorry, I forget to deploy the updated frontend. Could you please check it one more time?

Copy link

@Vladlan Vladlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Final mark 8/8.

@generalov generalov merged commit cd92a1f into master Nov 17, 2020
@generalov generalov deleted the task5 branch November 17, 2020 08:17
generalov pushed a commit that referenced this pull request Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants