Is there a way for GraphQL resolver to resolve data source from endpoint exposed by a lambda function generated by CodeStar?
The examples provided in the AppSync docs shows how I resolve data from single lambda function, but in my case, I'm using AWS Codestar to generate a REST API using lambda, with several endpoints that returns different set of data.
For example, when I want to resolve a fetchPosts, i need to resolve it from https://my-prod-example-url/posts endpoint, not just invoke the lambda function.
I am on the AWS AppSync team. Http data sources are not available yet but they're very much on our roadmap.
Related
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.
I'd like to use apollo graphql in a lambda and I found AppSync is for graphql and API Gateway is for REST. Do I have to use AppSync for that?
I also find out a library apollo-server-lambda which can be used with serverless but I don't want to use serverless because all my infrastructure code is written in Terraform. I don't want to bring another IaC library in my application.
So is there a way to use API Gateway with apollo graphql in lambda? If yes, how should I declare API Gateway route for that?
Not really. You can just use the API gateway, Lambda, and Apollo Server. Install the npm library apollo-server-lambda and Import the required modules.
The current version of Apollo Server Lambda: 2.17.0
You can create a GraphQL handler using the function createHandler provided by Apollo server Lambda.
I am not sure about how it is done using Terraform but you can just declare a route to your handler function via the API gateway.
Make sure your GET and POST requests route to the same handler.
Refer to this documentation for more details: https://www.apollographql.com/docs/apollo-server/deployment/lambda/
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.
I am trying to call sagemaker inference endpoint from api gateway with AWS Integration.I don't want to use lamdba in between of API gateway and sagemaker runtime. I followed this doc to setup api gateway method but it fails.
How can i call sagemaker inference endpoint from API gateway?
Web Browser ----> API Gateway ----> Sagemaker endpoint
API Gateway supports integration with AWS services directly (without the Lambda). You can follow the instructions at https://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-aws-proxy.html.
When you go to Step 4 in the instructions above, for the AWS Service option, you can choose 'SageMaker Runtime' to target the invoke endpoints.
API Gateway can be used to front an Amazon SageMaker inference endpoint as a REST API, by making use of an API Gateway feature called mapping templates. This feature makes it possible for the REST API to be integrated directly with an Amazon SageMaker runtime endpoint, thereby avoiding the use of any intermediate compute resource (such as AWS Lambda or Amazon ECS containers) to invoke the endpoint. The result is a solution that is simpler, faster, and cheaper to run. See this blog post for more detail on how to configure the API Gateway mapping templates against the Sagemaker runtime endpoint.
it's a long shot since it's an old question but somebody might end up here.
Reading the first section of the documentation about calling the inference endpoint in sagemaker, you'll find that you can only call it with a POST and pass your input data in the body.
https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_runtime_InvokeEndpoint.html
So it might be that you created a GET method in API Gateway and that you need to map your request parameters to a body payload or simply set up a POST method instead.
I am new to this whole serverless framework. I created my first serverless function as documented here https://www.npmjs.com/package/serverless#quick-start. Next when I do a "serverless invoke" it works. I am confused how this works, the questions I have around this are
There does not seem to be an API gateway created so how can it invoke?
There are also stages mentioned in the serverless.yml file, I'm not sure what these translate to
Any help on this is highly appreciated.
First of all the default code comes with the AWS template, is only having a Lambda function declared. Let me try to answer your questions inline.
There does not seem to be an API gateway created so how can it invoke?
Yes, since there is no API Gateway created, its not possible to invoke the Lambda through URLs. However, it is possible to invoke the Lambda using AWS CLI or SDKs which is what Serverless Framework is providing with "serverless invoke". To create a API Gateway, you need to add an event object to the function code as shown below.
functions:
hello:
handler: handler.hello
events:
- http:
method: get
path: hello
There are also stages mentioned in the serverless.yml file, I'm not
sure what these translate to
When you define a stage in serverless.yml file, after the deployment, it creates a stage in API Gateway including it in the API Gateway URL path as shown below.
https://your-api/<stage-you-defined>/resurce-methods
Note: that if you setup a custom certificate for API Gateway, then you have option to setup your own custom paths.
Also its important to note that, although API Gateway supported this feature to have different stages(e.g test, staging, production) of a Single API Gateway deployment, latest Serverless Framework doesn't use this feature. Instead when you define a new stages, it will deploy a whole new API Gateway with the new stage. Serverless Framework has the argument for separating the API Gateway and having a single stage to self-contain each stage for isolation.
You can attach an API gateway for invoking your lambda
Or
You can get event driven. Where your lambda gets invoked in response to some events like a new message in AWS SNS or when a new object gets created in S3
Or
You can have scheduled invocations using cloudwatch trigger events
For a comprehensive list of events that can invoke lambda see Invoking Lambda Functions
As documented in AWS Regions and Endpoints there are HTTPS endpoints for Lambda. For example, in the us-east-1 region the endpoint is https://lambda.us-east-1.amazonaws.com. This is how you're able to call a Lambda directly without the API gateway. API gateway can add additional functionality and puts a full HTTP protocol on top of a Lambda.