Without an API Gateway, you directly invoke the Lambdas function using different function URLs, with any HTTP methods as in previous workshop:
curl 'https://u2z6j6noy3vnrynejsjqmkgiry0asnnm.lambda-url.ap-southeast-1.on.aws/'
curl 'https://qzpsv22gd3s4qbnfwz2v5yefoy0dmipa.lambda-url.ap-southeast-1.on.aws/' \
-H 'content-type: application/json' \
-d '{ "id": "a3127179-6ba4-4c3b-855a-4f65d4ee6345" }'
curl 'https://zvybyad2wvq5dto3upm2mgtcwa0epmul.lambda-url.ap-southeast-1.on.aws/' \
-H 'content-type: application/json' \
-d '{ "name": "First Cloud Journey", "email": "fcj@example.com" }'
curl 'https://hk3icryf6br2ociwan5ier2gqe0gyaoi.lambda-url.ap-southeast-1.on.aws/' \
-H 'content-type: application/json' \
-d '{ "id": "bcfe3cf9-1607-489e-8501-f99c194e6cc9", "email": "fcj@aws.com" }'
curl 'https://5ywq2njgsehqpl3xl2nrs334ue0inscy.lambda-url.ap-southeast-1.on.aws/' \
-H 'content-type: application/json' \
-d '{ "id": "bcfe3cf9-1607-489e-8501-f99c194e6cc9" }'
Notice each time, you make a HTTP call to a different URL, you - as the end user - are handling the routing to the API for CRUD operations.
After integrate the Lambda functions to the API Gateway, our architect now looks like this:
After integrate the Lambda functions to the API Gateway with the type of REST API,
When an other AWS service directly invoke your Lambda function, that’s service is called a trigger for your Lambda function.
In our case, the API Gateway is acting as a trigger for the Lambda functions.
Under the hood, when we call the API Gateway - an event occurs in API Gateway:
API Gateway generates data for that occurred event
The data is in JSON format contains
This generated data is also know as generated event (or in short event).
Congratulation, you just create your first event-driven architect in AWS.
Replace https://pg6xn32zdc.execute-api.ap-southeast-1.amazonaws.com/dev
with your API’s Invoke URL.
# Make a GET request to /users path (to invoke list-users)
curl 'https://pg6xn32zdc.execute-api.ap-southeast-1.amazonaws.com/dev/users'
# Make a POST request to /users path (to invoke create-user)
curl 'https://pg6xn32zdc.execute-api.ap-southeast-1.amazonaws.com/dev/users' \
-X POST \
-H 'content-type: application/json' \
-d '{ "name": "First Cloud Journey (API)", "email": "fcj-api@example.com" }'
# Make a GET request to /users/{userId} path (to invoke get-user)
curl 'https://pg6xn32zdc.execute-api.ap-southeast-1.amazonaws.com/dev/users/5aab87c6-1328-44c9-98c6-c556c1351591'
# Make a PATCH request to /users/{userId} path (to invoke update-user)
curl 'https://pg6xn32zdc.execute-api.ap-southeast-1.amazonaws.com/dev/users/5aab87c6-1328-44c9-98c6-c556c1351591' \
-X PATCH \
-H 'content-type: application/json' \
-d '{ "name": "First Cloud Journey (API)", "email": "fcj-api@aws.com" }'
# Make a DELETE request to /users/{userId} path (to invoke delete-user)
curl 'https://pg6xn32zdc.execute-api.ap-southeast-1.amazonaws.com/dev/users/5aab87c6-1328-44c9-98c6-c556c1351591' \
-X DELETE
If you still keep the function URLs in previous workshop, now you can delete all of them. The API Gateway can invoke these Lambda functions without the function URLs.