Questions tagged with Amazon API Gateway
Content language: English
Sort by most recent
Hello,
I am working on Build a serverless web application using Amplify, Cognito, API Gateway, Lambda & DynamoDB use case
https://aws.amazon.com/getting-started/hands-on/build-serverless-web-app-lambda-apigateway-s3-dynamodb-cognito/module-1/
My question is have created a Repository name "wildrydes-site". Now i am trying to perform Populate git repository i have created the bucket and object . As per the use case which html file i have upload to get the same website which is shown in the use case. Can somebody help me from where i get same website file to upload also after uploading the file do i have to run these commands:
a. Change directory into your repository and copy the static files from S3:
cd wildrydes-site
aws s3 cp s3://wildrydes-us-east-1/WebApplication/1_StaticWebHosting/website ./ --recursive
b. Commit the files to your Git service
$ git add .
$ git commit -m 'new'
$ git push
Please suggest.
Thanks,
Hello,
I've developed an app for Slack but I've been having trouble starting it for a while now.
For those who don't know, the slack api requires a response within 3 seconds for user interaction requests, if this time passes it generates an error and the application does not work as it should.
I came to solve this problem, creating a lambda that runs every 3 minutes, invoking the main lambda, but I don't think it's the best way to do it.
With that I decided to create a lambda with provisioned concurrency, leaving 3 lambdas started. I think it was the best choice.
Turns out it's not working as it should. When I make the call, the API gateway is pointing to $LATEST, causing it to start a new lambda and I get timeout errors.
The configuration was done correctly as you can see:



Now when I make the calls it's creating a new container and pointing to the $LATEST version instead of pointing to the started lambdas. Version 42 lambdas receive one request or another at random as you can see in the logs. I really don't understand what's going on.

Hi there,
I'm looking for some suggestion here. I have over 1000 publicly accessible endpoints, all pointing to the same NLB, as CNAMEs. NLB does a TCP proxy and sends it to a pair of HA-Proxy, where TLS off-loaded and the host_header gets rewritten to a local domain, like: `www.example.com => main.example.net.local`, `www.mydomain.co.uk => main.example.net.local` etc. but it's becoming a huge overhead with monster ha-proxy config file. Hence I'm trying to replace the ha-proxy with some sort of native AWS services. I know ALB can terminate the TLS but couldn't find anything in th e AWS docs that it can rewrite the host header and can also add some custom headers. Thought about AP Gateway but I think many to one mapping's gonna be challenging? Does anyone have any suggestions about what AWS services (one or combine) can replace the ha-proxy functionalities?
-S
I want to create an API Gateway, that uses HTTP protocol, in my private VPC so that only the services inside this VPC can hit this API Gateway. There is an [article](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-private-apis.html) on creating private API for API Gateway but it is only for REST APIs. Also, while creating the API Gateway for HTTP, I could not find the VPC configuration option. Is it possible to create a private API Gateway for HTTP?
Is there a way to allow a trailing slash or follow a 308 redirect for an OIDC discovery endpoint using the JWT Authorizer?
I'm currently using next.js with `trailingSlash: true` and some middleware that adds the .well-known/openid-configuration endpoint. Unfortunately next.js added a "/" suffix to make it .well-known/openid-configuration/ and the HTTP API gateway responds with the following header:
```
www-authenticate
Bearer scope="" error="invalid_token" error_description="non-200 status code received from OIDC discovery endpoint"
```
Is there a way to workaround this? Is this a bug or a strict adherence to the spec?
Any help would be appreciated,
Dave
try {
const headObject = await s3.headObject(params).promise();
const fileSize = headObject.ContentLength;
const readStream = await s3.getObject(params).promise()//.createReadStream();
console.log(readStream)
//const fileContent = readStream.Body.toString('utf-8');
// Set headers for the response
const headers = {
//'Content-Length': fileContent,
'Content-Type': 'application/pdf',
//'Content-Disposition': `attachment; filename=${key}`,
'Accept': 'application/pdf' //'application/octet-stream'
};
const imageBuffer = Buffer.from(readStream.Body);
const imageBase64 = await base64.fromByteArray(imageBuffer).toString('utf-8');
console.log(imageBase64)
const response={
statusCode: 200,
headers,
body: imageBase64//readStream//.toString("base64"),
//isBase64Encoded: true,
};
//const str = await response.body.transformToString();
//console.log(response)
return response
// Pipe the S3 object stream to the response
//readStream.pipe(callback.response);
} catch (error) {
console.error(error);
// callback(error);
}
};
exports.handler=handle
Hi,
I tried to create pcluster API using "AWS Doc: https://docs.aws.amazon.com/parallelcluster/latest/ug/tutorials_06_API_use.html.
But im getting error when i try to POST or PUT methods from apigateway.
{
"message": "Bad Request: Configuration must be a valid YAML document"
}
I have created a pcluster API as mentioned in the aws docs. When i run this from cli it works. When i try to run from API gateway or postman im getting error.
Please advise how to fix this issue.
Thanks!
In API Gateway, to push a message to a connected WebSocket client, you're supposed to send a `POST` request to [API Gateway's @connections API](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html).
My question is:
* Will this `POST` request block until the message has been sent over the network?
* Or, if it returns sooner than that, is it at least guaranteed to be seen by the client before a subsequent `POST`?
I can't find this guaranteed anywhere in the API Gateway docs, but the usability of AWS API Gateway for WebSocket APIs would seem to hinge on this. If there is no such guarantee, the client could theoretically see messages in a random order.
Hi
We would like to protect our APIs developed on AWS API Gateway with OAuth2.0. I am not able to find enough documentation on this. Does anybody guide me on how to implement OAuth2.0 on AWS API Gateway for authentication and authorization?
Hey all! Hope your are doing well. I have been trying to write a query service for some internal databases in my VPC. My current setup is API Gateway with a Lambda that queries the database which works fine, but unfortunately I ran into two issues:
- API Gateway default timeout is 30s which is not very long for queries.
- Lambda response size limit is 6mb, which is fine but also not suitable for the biggest queries.
Are there any serverless services I can use to solve this problem? I do require custom domain / authentication. Some solution I thought of were:
- Chunking request, which should work fine but I think 30s is still not very long. It is a temporary solution for now.
- Using ALB as a "api" to trigger lambdas, which would fix the timeout, but response size limit is still 6mb.
- Hosting my own API on a EC2/Container, which I can do but I like serverless solutions.
- Using websockets, but it seems harder to attach existing apps to a WS compared to a REST api.
If somebody has some input would really appreciate it! Thanks in advance.
Hello,
I am practicing using SAM CLI to make and deploy Lambda functions as APIs. I am running into issues enabling CORS on the API gateway associated with my lambda function. I have tried both configuring CORS in my template.yaml file and going into the API gateway console and enabling CORS manually.
The lambda function is a simple hello world function that takes in 1 parameter which is a name and returns " {name} says hello world!". I have tested the api locally using a react app to invoke the api call and everything works fine. That is not the case for when its deployed to AWS.
Here is my template.yaml file:
```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
apple-app Sample SAM Template for apple-app
# More info about Globals:
Globals:
Function:
Timeout: 3
MemorySize: 128
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python3.9
Architectures:
- x86_64
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get
RestApiId: !Ref AWS::ApiGateway::RestApi
Cors:
AllowMethods: "'GET, POST'"
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
AllowOrigin: "'*'"
Outputs:
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Arn
```
Am I configuring the implicit HelloWorld api correctly to enable CORS?
Since my configuration with the yaml file didn't work correctly. I tried manually enabling CORS by going into the API gateway console and clicking the button "Enable CORS and replace existing CORS headers". This is the response I get with an error:
✔ Add Access-Control-Allow-Headers, Access-Control-Allow-Methods, Access-Control-Allow-Origin Method Response Headers to OPTIONS method
✔ Add Access-Control-Allow-Headers, Access-Control-Allow-Methods, Access-Control-Allow-Origin Integration Response Header Mappings to OPTIONS method
✖ Add Access-Control-Allow-Origin Method Response Header to GET method
✖ Add Access-Control-Allow-Origin Integration Response Header Mapping to GET method
Your resource has been configured for CORS. If you see any errors in the resulting output above please check the error message and if necessary attempt to execute the failed step manually via the Method Editor.
! The Empty Model does not exist, and retry resource creation without it.
I am not sure what I'm doing wrong, so any help would be greatly appreciated.
Thank you.
This question is related to https://repost.aws/questions/QUGMi_eNmkTB-nVwLdze9eKA/what-are-the-benefits-of-using-amazon-cloud-front-together-with-amazon-api-gateway where REST API Gateway performance benefits were discussed when using along with CloudFront.
What about CloudFront distribution in front of **HTTP API Gateway**. Does it provide the same benefits in terms of performance? As far as I'm concerned this type of API Gateway uses Regional API endpoints. I wonder if I would benefit from a CloudFront distribution pointing to a HTTP API Gateway in a single region?