GET aws lambda functions list using rest - amazon-web-services

I want to write a unit test for the availability of AWS lambda functions. Is there any way to GET AWS lambdas list. I know using CMD we can get the list of AWS function. But I want any other way to get the lambda functions list.
After research, I find out a rest API of all AWS services. But I didn't understand how to use them.
I found out AWS HTTP calls, links are attached https://docs.aws.amazon.com/general/latest/gr/rande.html.

Yes, you can do that using AWS Infrastructure REST API interface.
To do so,
You first need to create a signature 4 authentication key for every call you make.
Reference: Authenticating Requests (AWS Signature Version 4)
Then you need to pass it via Authorization header in any REST request.
Reference: Authenticating Requests: Using the Authorization Header (AWS Signature Version 4)
Finally, call using ListFunctions API.
Reference: ListFunctions
Call Example:
GET
/2015-03-31/functions/?FunctionVersion=FunctionVersion&Marker=Marker&MasterRegion=MasterRegion&MaxItems=MaxItems
HTTP/1.1
This gives you the list of Lambda functions deployed.
Hope it helps.

Related

How to use aws lambda without HTTP api?

Since there is aditional costs for using HTTP and REST apis on AWS lambda, i would like to know if i could make AWS Lambda receive gets and posts without the need of these HTTP API services.
In this example it seems to be possible:
https://github.com/serverless/examples/tree/master/aws-node-simple-http-endpoint
You will need to use the API Gateway to expose your lambda. Your example is actually using an API Gateway, because the endpoint is execute-api.us-east-1.amazonaws.com and that is the Amazon API Gateway Data Plane.
Just to be clear; if you need to expose the Lambda externally you need to use the API Gateway. If the Lambda needs to be invoked internally then you don't need the API GW.
Best regards
Lambda also exposes a client API in all languages. Therefore, you can invoke a Lambda function by using the client API (not use API Gateway if you prefer). For example, assume you want the ability to invoke a Lambda function from a Java web app. In this situation, you can use the LambdaClient object to do so. You can find an example here:
https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/lambda/src/main/java/com/example/lambda/LambdaInvoke.java

Call AWS Lambda from Step Funtion using specific URL with parameters

I am trying to orchestrate UI calls using step function with the minimal impact. Currently I have a lambda function that can be called using different URLs via API gateway, for instance, following URLs are used to call the same lambda:
http://base.url/orders/get/order/{userid}
http://base.url/orders/get/allorders/
I know that it isn't a best practice for lambdas, but we have what we have. Now I need to add a step function between API gateway and lambda to orchestrate calls. I need step function to be able to call step function using these urls, but I cannot understand how to do that.
Here are some links that I already checked:
https://docs.aws.amazon.com/step-functions/latest/dg/concepts-input-output-filtering.html
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-paths.html
https://docs.aws.amazon.com/step-functions/latest/dg/connect-parameters.html
Is there a way to do what I need to do?
It sounds like you just need to format the message to the lambda in a way that looks like what would be coming from the API Gateway. If that's the case you can see what an API Gateway request would look like by selecting Amazon API Gateway AWS Proxy from the lambda test events in the console. From there you should be able to modify the payload to match your needs.

Create an api in api gateway to invoke a lambda function

I am working on a project and trying to use API Gateway to invoke a lambda function. The lambda function is used to update a DynamoDB item. The DynamoDB table is used to keep a running count of visitors to a web page. I need to create an API to invoke the lambda function but I'm not sure how to create the API. Any assistance is appreciated.
General steps would be:
Create AWS_PROXY integration between API Gateway and your Lambda function. The example of this is in the AWS tutorials: Set up Lambda proxy integrations in API Gatewa and in Tutorial: Build a REST API with HTTP proxy integration
Add/amend execution role to your function allowing it to access DynamoDB. This is exemplified in the AWS tutorial: Using AWS Lambda with Amazon DynamoDB.
Test the API. It can be done directly in API gateway console, or using external tools such as curl or Postman.
I figured out my issue. In my lamdba function, I needed to change the output to a JSON object. Once I made the change, I was able to get my API working. Here is a link to the fix.

AWS API Gateway call Lambda versions by header information

I've read a lots of API versioning hints for integrating AWS API Gateway with Lambda functions. But most of them used the URL to provide the version number e.g. /v1/orders
But I do not want to use this pattern. Instead I'd like to evaluate the header information to retrieve the requested version.
What I want to do is the following:
configure API Gateway (via CloudFormation) in order to define only /orders
use request mapping to read a header 'version'
call a lambda function e.g. getOrders:v1 if 'version' header is set to 'v1'
Is this possible with AWS Api Gateway? Or is there a similar approach that doesn't use URL to distinguish between versions?
I saw a solution by using stage variables:
https://dzone.com/articles/api-versioning-approach-with-aws-api-gateway
Regarding this approach: Is there an equivalent to ${stageVariables.v1fn} for headers? E.g. ${request.headers.version}?
A possible solution would be to use a lambda which dispatches the request to the lambda in question, API Gateway unfortunately only supports one lambda per endpoint and method

Is it possible to use AWS Lambda to request an oauth 2.0 token?

I am looking for ways to avoid creating an ec2 instance in order to have a valid callback URL to perform the oauth handshake.
I plan to use Lambda to connect to a remote API, but I need to be able to get the token first, which is valid only for 6 hours.
Is there any way I can make the handshake via Lambda functions?
I think Lambda along with API Gateway offer a good solution. API Gateway allows you to create a persistent, publicly accessible HTTP endpoint. You can define specific 'resources' that map HTTP methods to lambda function calls.
I'm not especially familiar with OAuth 2, but I'm imagining something like this: In API Gateway, define a resource '/callback' with a GET method that invokes your Lambda function.
Register the API Gateway endpoint as your application's callback URI, which would look something like this:
https://c1bql2cdxy.execute-api.us-east-1.amazonaws.com/callback
By doing so, the remote service will invoke your lambda function, which can then read the authorization token from the request and use it however needed, whether that involves 1) storing the token in a database for future use (and reuse) by other services, 2) directly invoking the services within the same Lambda function, etc.