apig | Golang RESTful API Server Generator | REST library
kandi X-RAY | apig Summary
kandi X-RAY | apig Summary
apig is an RESTful API server generator.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of apig
apig Key Features
apig Examples and Code Snippets
Community Discussions
Trending Discussions on apig
QUESTION
React/JS newbie here.
I've got a simple react app with the page fetching a number from ItemCounter
API-Gateway. The code works right now and it's able to fetch a value from the lambda/apig url.
ANSWER
Answered 2022-Mar-12 at 08:16You need to add one more useEffect
inside which you need to set an interval for every 5 seconds.
QUESTION
I want to deploy a APIGateway with mock integration for testing via serverless using this example.
However when I try to deploy it I get the following error:
...ANSWER
Answered 2022-Feb-21 at 14:57The error normally occurs when you are testing the Serverless Framework in a directory with only the serverless.yml file. This looks like a bug with the Serverless Framework.
Your project structure must be like the following:
QUESTION
new to the CDK and relatively new to AWS
The IssueI'm following this tutorial which includes creating a fargate based private API, and accessing it on the public internet through an ec2 instance which is publicly exposed.
I'm picking through, minimally correcting various issues which gets everything running. It comes time to build with:
...ANSWER
Answered 2021-May-25 at 15:56The timeout was due to a misnamed ECR which the bookService
was attempting to access. To generalize this answer a bit, if there's a timeout it may be good to record which resources timed out and sanity check all the constituent elements.
QUESTION
I have some TypeScript code that uses CDK to create an API Gateway and a Lambda. It works and deploys to a standard AWS URL. So far so good.
I now need to transfer the API Gateway so that it operates on a custom domain, so that it can set a cookie in a web app. This is proving far harder, and I suspect I am having difficulty because I am new to TypeScript, AWS, and CDK all at the same time. There are a number of documentation resources on the web, but most would require me to rewrite the precious little working code I have, which I am reluctant to do.
I have created a certificate manually, because that requires validation and thus it does not make sense to create it in code. Other than that I want all other resources to be created by CDK code in a Stack. In my view, it defeats the purpose of CDK if I have to configure things manually.
ProblemThe below code deploys everything I need to gatekeeper.d.aws.example.com
- a HostedZone, an ARecord, a LambdaRestApi and a Function (lambda). However it does not work because the NS records newly assigned to gatekeeper.d.aws.example.com
do not match the ones in the parent d.aws.example.com
.
I think this means that although d.aws.example.com
is "known", the gateway
subdomain cannot delegate to it.
Here is my working code:
...ANSWER
Answered 2021-Mar-17 at 20:23I have consulted two AWS experts, and they do not favour cross-account operations. One said:
This is an anti-pattern, since it requires permissions to remain even after the stack is deployed. What happens if a cross-account operation has to roll back and that permission is revoked? It would result in the app being stuck in a middle/undefined state (the local part is rolled back, but the remote part cannot be rolled back due to an access violation).
The other advised:
Cross-account CDK is hard.
It is much better to split your stacks into two or more operations, so you can run them independently. This applies nicely to "one off" operations like DNS delegation - realistically you are not going to change the zone delegation for your Stack unless you destroy it, which you are not going to do until you actually don't need it. Thus, there is no reason for the zone information to change for the lifetime of the system.
This also works well where you have an app and a database, and you want the ability to take down your app without destroying the data.
So, this is an answer in the sense that some folks will say "don't do it". However, it looks like AWS has the ability to do it, so answers in that direction are still welcome.
QUESTION
On of my API Gateway logs entries indicates a timeout and I'm investigating where it's coming from. The log entry has an X-Ray trace ID but when I use X-Ray to search for it, I get "Data not found".
I'm expecting at least one node, the APIG , to show up in X-Ray. What am I missing?
API Gateway CloudWatch Logs Insights I cannot find trace for
query-string:
...ANSWER
Answered 2021-Mar-13 at 18:18Having trace ID doesn't mean that get sampled.
Trace Id is only one part of Trace Header. For example look at this:
QUESTION
I've a Lambda which makes an API request to a service and get a list of matches for a given identifier. Once it gets a list of matches it updates a DynamoDB table in the following way:
requestId (partitionKey) ID matches status uuid1 ID1 [match1,match2, match3...] FOUND_MATCHESFor each match in this table, a message is sent to SQS which is listened to by a Lambda. For each match, the Lambda will make a call to a different service and update a table which keeps track of the matches execution.
Match (partitionKey) requestId (sortKey + GSI Partition Key) match1 uuid1 match2 uuid1 ... ... match10 uuid1Now given the requestId, I would like to know if there are entries in the 2nd table for all matches.
One option I'm thinking is look up the first table via the requestId and it will give the list of matches, then it will call the 2nd table multiple times via the primary key, sortKey combination and compile a result. The other option is instead of looking up via primary key/sort key for 2nd table, it will look via a GSI Parition key on the requestId column and get all the matches at once (in a paginated list).
I would like to expose this operation via an API call, and I'm wondering if I'll run into APIG 30 seconds timeout (I know I'll need to run some experiments with my dataset, but just wanted to see if there are other options I can consider before doing this). If number of matches exceed say 50,000. And each get call roughly takes 20ms, it will take about 50,000 * 20 = 1000 seconds which is way more than APIG limit. Maybe batch call might help a bit, but not sure there is much room there.
Essentially I would like to update the status in the first table from FOUND_MATCHES
to ALL_MATCHES_PROCESSED
.
- Ideal option is automatically the state gets updated
- A Get status API essentially triggers the calculation and updates the state (Maybe make this async to get past the 30seconds APIG limitation)
ANSWER
Answered 2021-Mar-02 at 09:40I'd probably do it like this, since I'm a fan of the single table design pattern:
PK SK type attributesREQ#
META
REQUEST
matches: [a,b,c]; unprocessed_matches: 3; status: FOUND_MATCHES
REQ#
M#a
MATCH
result
REQ#
M#b
MATCH
result
REQ#
M#c
MATCH
result
Whenever a new request comes in, you write a REQUEST
to the table with the matches and an unprocessed_matches
attribute that counts all matches.
Then you have a Lambda function "stream-processor" that listens to the stream of that table.
When a new REQUEST
item shows up (no old image present), it creates the tasks in your SQS queue.
The worker process on your SQS queue then calls the 3rd party API and records the result. The result is then written to the table through a transaction with two items:
- An
UpdateItem
call, that decrements the unprocessed_matches value for the request id by one. - A
PutItem
call, that creates theMATCH
item.
The transaction here is important, you want this to be an all or nothing operation.
Your stream-processor lambda then has a second job.
Whenever there is update to a REQUEST
item, it should check, if unprocessed_matches <= 0 and status = FOUND_MATCHES
.
When that's the case, it should update the REQUEST
item and set the status to ALL_MATCHES_PROCESSED
.
Your original Lambda that made the first request can periodically poll the status of the item in the table.
This design also let's you easily get everything about a request by a simple Query
to the partition key with the request ID.
You should be aware that there is a 400KB item size limit in DynamoDB, depending on how long your matches list gets, this might become a problem.
QUESTION
What is the AWS recommendation for hosting multiple micro-services? can we host all of them on same APIG/Lambda? With this approach, I see when want to update an API of one service then we are deploying API of all services which means our regression will include testing access of all services. On the other hand creating separate APIG/Lambda per service we will end up with multiple resources (and multiple accounts) to manage, can be operational burden later on?
...ANSWER
Answered 2020-Nov-11 at 23:42A microservice is autonomously developed and should be built, tested, deployed, scaled, ... independently. There are many ways to do it and how you'd split your product into multiple services. One pattern as an example is having the API Gateway as the frontdoor to all services behind it, so it would be its own service.
A lambda usually performs a task and a service can be composed of multiple lambdas. I can't even see how multiple services can be executed from the same lambda.
It can be a burden specially if there is no proper tooling and processes to manage all systems in a automated and escalable way. There are pros and cons for any architecture, but the complexity is definitely reduced for serverless applications since all compute is managed by AWS.
AWS actually has a whitepaper that talks about microservices on AWS.
QUESTION
Using CDK to connect ApiGateway to a lambda, we first create a RestApi(), and then create a LambdaIntegration to connect the Apigateway to a lambda. How do you do this when working with a lambda Alias?
How to point ApiGateway to a specific Lambda alias explains how to connect ApiG to a Lambda alias without CDK. How can this be translated to CDK?
Our goal is to add provisioned concurrency and autoscaling to a lambda used with API Gateway.
...ANSWER
Answered 2020-Aug-20 at 06:57LambdaIntegration
Function gets handler: IFunction
as a parameter which is the lambda object.
With that been said, you can import the lambda version you want using the following code snippet:
QUESTION
I want to use AWS CDK to define an API Gateway and a lambda that the APIG will proxy to.
The OpenAPI spec supports a x-amazon-apigateway-integration
custom extension to the Swagger spec (detailed here), for which an invocation URL of the lambda is required. If the lambda is defined in the same stack as the API, I don't see how to provide this in the OpenAPI spec. The best I can think of would be to define one stack with the lambda in, then get the output from this and run sed
to do a find-and-replace in the OpenAPI spec to insert the uri, then create a second stack with this modified OpenAPI spec.
Example:
...ANSWER
Answered 2020-Jun-04 at 18:40It looks like what I'm after is tracked by this CDK issue. In the meantime, I was guided by the comment on that issue here and came up with a workaround.
I used https://github.com/spullara/mustache.java to parse my OpenAPI spec file and replace template values in it that referenced the invocation ARN of the API gateway (that itself references the Lambda ARN).
QUESTION
My stage has xray tracking enabled and I can see X-Amzn-Trace-Id is coming back from API gateway, moreover, I'm able to see the whole trace from APIG to Dynamo db. I would like to save this trace id to the table, so we can debug it more efficiently, but when I map an integration like
...ANSWER
Answered 2020-May-14 at 01:59Ok, it seems that solution from aws documentation doesn't work, however Xray id present in headers, so we can do
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install apig
Finally, just build as normal go code. After that just execute the server binary. For the first time, you may want to use AUTOMIGRATE=1 when running the server.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page