Questions tagged with Amazon API Gateway
Content language: English
Sort by most recent
I wish to fetch complete request to a API Gateway (REST API). I've tried Full Request and Response Logs, Access Logs and XRay but haven't been able to fetch complete request. Any help would be appreciated.
Thanks
How to attach authorizer to api gateway V2 route in aws cloudformation?
I am using Api Gateway v2 and cloudformation.
I am using stages "prod" and "stg" I would like to work on separate lambda stg and prod.
In AWS console it is just one click of one button "Attach Authorization" in "Routes" section
I am using simple authorizer:
My cloudformation looks like this:
```
Authorizer:
Type: 'AWS::ApiGatewayV2::Authorizer'
Properties:
ApiId: !Ref ApiGateway
AuthorizerPayloadFormatVersion: 2.0
AuthorizerResultTtlInSeconds: 5
AuthorizerType: REQUEST
AuthorizerUri: !Join
- ''
- - 'arn:'
- !Ref 'AWS::Partition'
- ':apigateway:'
- !Ref 'AWS::Region'
- ':lambda:path/2015-03-31/functions/'
- 'arn:aws:lambda:'
- !Ref 'AWS::Region'
- ':'
- !Ref 'AWS::AccountId'
- :function:${stageVariables.AuthorizerFunctionName}
- /invocations
EnableSimpleResponses: true
IdentitySource:
- '$request.header.Authorization'
Name: !Sub ${ProjectName}-gateway-authorizer
MyRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref ApiGateway
AuthorizationType: CUSTOM
AuthorizerId: !Ref Authorizer
RouteKey: 'POST /posts/all'
Target: !Join
- /
- - integrations
- !Ref PostsLambdaIntegrationGet
```
Authorizer lambda body:
```
import json
# import jwt
def lambda_handler(event, context):
print('*********** The event is: ***************')
print(event)
print('headers is:')
print(event['headers'])
print('headers Authorization is:')
# !!!!! DONWCASE by postam or api !!!!! "A" -> "a"
print(event['headers']['authorization'])
if event['headers']['authorization'] == 'abc123':
response = {
"isAuthorized": True,
"context": {
"anyotherparam": "values"
}
}
else:
response = {
"isAuthorized": False,
"context": {
"anyotherparam": "values"
}
}
print('response is:')
print(response)
return response
```
BTW I do not see this option in cli [apigatewayv2 cli documentation](https://docs.aws.amazon.com/cli/latest/reference/apigatewayv2/index.html) too.
BTW I asked this question on [attach authorizer to api gateway V2 route in aws cloudformation](https://stackoverflow.com/questions/75225545/attach-authorizer-to-api-gateway-v2-route-in-aws-cloudformation) too.
1) I attached authorizer.
2) I deployed api.
3) I checked authorizer with hardcoded lambda name (it works), it verifies my lambda and permissions are correct.
Hi,
I have created a ASP.NET Core Web API project using below option from Visual Studio. Actually I needed to install AWS Toolkit for Visual Studio to use this template.

I have deployed this ASP.NET Core Web API to AWS Lambda using the option of right clicking the project and using the option

When I try to deploy below popup appears but it doesn't give options to deploy in multiple environments.

Now I want same Web API to deploy for different environment like test environment so how can I deploy the same.
I used to use the REST api, but since v2 i find myself using it more.
Is there a proper way to return data "neatly" other than manipulating the database response before returning?
I used to use the model feature with REST (v1). I was wondering what's the recommended way to do the same here. tnx.
Here's an example of what i'm trying to do.
I'm selecting specific columns, while avoiding the error:
> An error occurred (ValidationException) when calling the UpdateItem operation: Invalid UpdateExpression: Attribute name is a reserved keyword "owner"
and since integers/floats return as a "Decimal":
> Object of type Decimal is not JSON serializable
i added the class to set them properly as integers/floats.
I'd be happy to get some heads up unrelated to my question too. Tnx.
```
import json
import boto3
from decimal import Decimal
class DecimalEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Decimal):
return str(obj)
return json.JSONEncoder.default(self, obj)
def lambda_handler(event, context):
try:
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('SomeTable')
response_body = ''
status_code = 0
response = table.scan(
ProjectionExpression="#col1, #col2, #col3, #col4, #col5",
ExpressionAttributeNames={
"#col1": "col1",
"#col2": "col2",
"#col3": "col3",
"#col4": "col4",
"#col5": "col5"
}
)
items = response["Items"]
mapped_items = list(map(lambda item: {
'col1': item['col1'],
'col2': item['col2'],
'col3': item['col3'],
'col4': item['col4'],
'col5': item['col5'],
}, items))
response_body = json.dumps(mapped_items, cls=DecimalEncoder)
status_code = 200
except Exception as e:
response_body = json.dumps(
{'error': 'Unable to get metadata from SomeTable: ' + str(e)})
status_code = 403
json_response = {
"statusCode": status_code,
"headers": {
"Content-Type": "application/json"
},
"body": response_body
}
return json_response
```
This just looks too much for a simple "GET" request of some columns in a table
Hi, I am working on a requirement wherein I have to restrict the incoming requests to Lamba function behind the AWS API Gateway to be less than 800 KB. This needs to implemented preferrably at the Gateway level and need to implement it in Terraform as Infrastructure-as-Code. I am thinking that AWS [WAF SizeConstraint](https://docs.aws.amazon.com/waf/latest/APIReference/API_SizeConstraintStatement.html) might be the answer but looks like it will only inspect up to 4096 bytes and also not sure how to implement a filter that rejects incoming requests greater than 800 KB body size in Terraform.
Thanks in Advance
We have a react based front end app. It uses amplify in front end to interact with cognito.
We use hosted cognito login page in our react web app.
When we send the access token to backend api backed by API GW which uses cognito to authorize and authenticate.
The issue is sometime the access is getting expired. It looks like the access token is available for 1 hour only.
How do we know whether the token is valid or not in front end code using aws amplify ?
If it is expired, how do we use amplify sdk/api to refresh and get the new token without refreshing the page ?
Note:
* When we manually refresh the page, it is working.
* We want to perform the api call make it as a successful api call without asking the user to manually refresh the page.
Need to design a mobile/web app and need suggestion on infra part.
I have decided to use application load balancer (ALB), but not sure should I have an API gateway as the entry point to the app or the application load balancer will be used as the entry point?
I am using Cognito's Authentication Code Grant. After logging in, a user is given a code inside the callback URL which is later exchanged for an `access_token`.
In my web application, after logging in, a user can access a "console" (similar to AWS). Each time the user interacts with the console (like accessing a service) it does it through an api in API Gateway.
Unauthenticated users should not access the console and all its services. Hence, the way I am doing this is that every time the user wants to make a request to these REST endpoints the `access_token` is required.
However, this `access_token` should be stored somewhere so that the user can pass it in the request headers for later calls.
Where should this `access_token` be stored?
Which is the right way to do this? Maybe requiring the `access_token` in every API endpoint is not right?
I'm creating a Spotify data analysis tool to communicate with the company API so I can provide a service on my web for people to see some insights of their spotify profiles. To do so, I need to incorporate the SSO on my web with the OAuth2.0 protocol (given by Spotify to use their API).
I would like to know if someone can guide me into the steps to do this since I have no prior experience working with external users authentication.
A few months ago, I set up a Lambda Function that is invoked through a API Gateway Integration. A few days ago I noticed that endpoint was returning HTTP 500 (Internal Server Error). When I went to check the Lambda function, the main console for Lambda showed no set up functions, with a red error box with no text, and next to the refresh button the message "Last Fetched 53 years ago". Through API Gateway I was able to access the Lambda function, but the code window is missing (not empty, missing), and when I go to the "versions" tab, I once again get the red error box with no text. Same thing when I tried the "aliases" tab, and to view the function url. Oddly, when I ran the built in test, it says it passed, but when I checked the browser devtools, it showed it returned a HTTP 403 (Forbidden) error. When testing the function url in Postman, I get the same HTTP 403 error.
When I tried to create a new function, I went through the wizard without issue, but pressing "Create Function" at the end gives me a spinner that after 30min is still spinning.
Honestly, I haven't a clue how to even approach trying to solve this issue, or even what the issue is. Any guidance or assistance would be very much appreciated.
I could not post data from this url :
https://onlinetestfrontend.s3.ap-northeast-1.amazonaws.com/student_form_apigatewaywithCors.html
can some one please help.
form post action :
http://springbootinmemory-env.eba-fedwtjib.ap-northeast-1.elasticbeanstalk.com/student
I Assume it is a free service ..please ignore if it is paid service or route to correct channel
I saw an earlier question but I have a specific question and some behavior from the server I can't find answers to.
Setup:
I have an API Gateway setup via VPC link. It has a GET method. It goes through a NLB and a ALB to a target EC2 hosting a SAP REST API. I see from the console and the REST spec that body requests for GET is not supported.
**However, what will happen if someone sends a GET request WITH a body to the API gateway? Will API Gateway simply drop the body?**
I presume the "best solution" here is to change it to a POST, if a request body is necessary?