Eshwari247 / init_exercises

0 stars 0 forks source link

Implement FizzBuzz and Rest server in Lambda #4

Open anu1667 opened 1 year ago

anu1667 commented 1 year ago

Deploy the Fizzbuzz program and Rest server created in #2 to AWS Lambda

Note: You can deploy just the typescript version of both

Eshwari247 commented 1 year ago

To run a function on AWS Lambda Create a Lambda function ->configure an event source that triggers the function's execution.

  1. AWS Management Console with IAM
  2. Lambda Function Create function
  3. Author the function code or container image or use an existing application.
  4. Configure the function details, such as the function name, runtime and execution role
  5. Write or upload the code in the code editor.
  6. Configure the function's memory, timeout,
  7. Define an Event Source trigger
  8. Test Function in Lambda console
  9. Deploy and Monitor AWS Lambda will automatically scale and manage the execution environment
  10. Monitor function's execution and logs using Amazon CloudWatch.
  11. Manage Versions and Aliases updates and rollbacks.
Eshwari247 commented 1 year ago

Successfully deployed JS fizzbuzz code on AWS Lambda Working on Serverless framework Also trying methods to code typescript on Lambda - AWS CLI and AWS SAM

anu1667 commented 1 year ago

As mentioned by Matt, You can drop the idea of implementing typescript code in lambda Nodejs runtime for this exercise. Just javascript is enough.

Eshwari247 commented 1 year ago

Serverless method to implement -

  1. Install Serverless Framework
  2. AWS access key & user name
  3. Initialize a New Serverless Service
  4. Edit serverless.yml - configure Lambda functions , REST API endpoints, region
  5. Write the handler lambda function
  6. Deploy service - serverless deploy
  7. Access & Test RESTApi
anu1667 commented 1 year ago

Once done, put up your links to access lambda here in the comments.

Also delete any unused resource on AWS.

Eshwari247 commented 1 year ago

GET - https://3y4miqooj9.execute-api.us-east-1.amazonaws.com/PROD POST - curl -X POST https://3y4miqooj9.execute-api.us-east-1.amazonaws.com/POST -d '{"a": 5, "b": 10}' lambda - REST API

Eshwari247 commented 1 year ago

POST - curl -X POST -d '{"a":5,"b":8}' https://rqv37rwp2b.execute-api.us-east-1.amazonaws.com/dev/hello GET -https://rqv37rwp2b.execute-api.us-east-1.amazonaws.com/dev/hello Endpoints generated via Using serverless framework

anu1667 commented 1 year ago

https://github.com/Eshwari247/init_exercises/blob/cbdca16feefa06b89d5712d70695ceb6a48fcf30/EX4/handler.js#L20-L28

If I try to replicate the else part, I get Internal server error. That is because in line 22 response is used before initialisation.