Open rhboyd opened 5 years ago
This is an interesting idea. Would be happy to work with someone to implement this. Leaving this up for +1's.
@keetonian I have a solution that I'm speaking to the API Gateway team about this week. I'd love to be able to add it to SAM
My goal was to make the API Integrations mimic the boto3 sdk calls so if you wanted an API that listed route53 hostedzones, it would look like
GetMethod:
Type: AWS::ApiGateway::Method
'Fn::Transform':
- Name: SimpleAPI
Properties:
AuthorizationType: NONE
RestApiId:
Ref: RestAPI
ResourceId:
Ref: SimpleProxyResource
HttpMethod: GET
Integration:
Credentials:
Fn::GetAtt:
- DDBReadRole
- Arn
Service: route53
Action:
Name: GetHostedZone
Parameters:
- Id: "myhostedzonename"
ResponseMaps:
# This would map the DelegationSet and HostedZone from the response to an apig response body that looks like
# {
# "myset": [response.DelegationSet],
# "hz": [response.HostedZone],
# }
Success:
- DelegationSet: "myset"
- HostedZone: "hz"
# this does the same for the InvalidInput exception that may be thrown
InvalidInput:
- Message: "error-message"
# this is behavior to perform for any other exception the service may return
Failure: #TODO
I would like to be able to use SAM to directly proxy requests from API Gateway to DynamoDB. It feels like Lambda sits at the center of SAM and almost all of the features are geared towards shuttling data through Lambda with as little friction as possible. If I wanted to create an API that allowed a user to POST some data, which was mapped to a DynamoDB PutItem request, then a lambda processed the stream of changes to DynamoDB, I wouldn't be able to easily do this today with SAM. I would have to create a function that sits behind the API and accepts the item, (maybe processes it), puts it in dynamo, then returns a status code to the client. This can take about 100ms per request and I'm capped at 1000 concurrent executions before my clients start to get error messages. By allowing a direct APIG<->DDB integration, the client gets a response in ~10m, I can batch updates to my Lambda function, and I can build a more event-driven architecture.
I think an awesome approach would be something like:
When a user performs a POST request the "id" field from the request body is mapped to the partition key, remaining fields in the body can be mapped to other items, then API Gateway puts the item directly in the Table and returns a response to the user.