Monday, 16 September 2019

Serverless - Integrating With API Gateway with Lambda Functions by Raj Gupta

In this section, we show how to create and test an API with Lambda integration using the API Gateway console. With the Lambda proxy integration, when a client submits an API request, API Gateway passes to the integrated Lambda function the raw request as-is.

[root@ip-172-31-82-149 amazing-api]# sls invoke -f hello { "body": "{\"input\": {}, \"message\": \"Welcome to Raj by serverless\"}", "statusCode": 200 } [root@ip-172-31-82-149 amazing-api]#

[root@ip-172-31-82-149 amazing-api]# cat serverless.yml

functions: hello: handler: handler.hello events: - http: path: results method: get

[root@ip-172-31-82-149 amazing-api]# cat handler.py

import json def hello(event, context): if event['httpMethod']=='GET': body = { "message": "Welcome to Raj by serverless", "input": event } response = { "statusCode": 200, "body": json.dumps(body) } return response



[root@ip-172-31-82-149 amazing-api]# export AWS_ACCESS_KEY_ID=AKIAWSYHFCM3Y6ZLJWN6
[root@ip-172-31-82-149 amazing-api]# export AWS_SECRET_ACCESS_KEY=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
[root@ip-172-31-82-149 amazing-api]# serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service amazing-api.zip file to S3 (432 B)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
........................
Serverless: Stack update finished...
Service Information
service: amazing-api
stage: dev
region: us-east-1
stack: amazing-api-dev
resources: 10
api keys:
  None
endpoints:
  GET - https://dkoi2da9zk.execute-api.us-east-1.amazonaws.com/dev/results
functions:
  hello: amazing-api-dev-hello
layers:
  None
Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing.
[root@ip-172-31-82-149 amazing-api]#


Now if access the api gateway URL https://dkoi2da9zk.execute-api.us-east-1.amazonaws.com/dev/results


2 comments:

  1. Hello everyone , here’s your opportunity for you to achieve your dreams of being a multi million dollar rich through trading , I once loss all I got through trading but was fortunate to come across a woman with great virtue and selfless heart (Mary ) i was introduce to her masterclass strategy while searching online which has revived me of all my losses and made me gain more and more . With her unique strategy you are entitled to daily signals and instant withdraw ,be rest assured of getting a refund of all your loss investment with any platform that has denied you in one way or the other in getting your money . Mrs Mary masterclass strategy is simply the best for beginners and those that are finding it difficult to succeed through trading she’ll help you with just a simple step . Email her ( maryshea03 @ Gmail .com) WhatsApp +1 562 384 7738 . Remember this is absolutely free!!!

    ReplyDelete