aws / aws/serverless-application-model
Proposal: Less server serverless applications
- Dominant language
- Python
- Stars
- 9.6k
- Forks
- 2.5k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 7
Description
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:
```yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: 'API Gateway to data store'
Resources:
StreamProcessor:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: '.'
Handler: 'routes/root.handler'
Runtime: 'nodejs8.10'
Events:
Events:
DynamoDB1:
Type: DynamoDB
Properties:
Stream:
'Fn::GetAtt':
- Table1
- StreamArn
StartingPosition: TRIM_HORIZON
BatchSize: 100
Table1:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: id
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Events:
PUT:
Type: 'Api'
Properties:
Path: '/test'
Method: 'post'
UPDATE:
Type: 'Api'
Properties:
Path: '/test'
Method: 'update'
```
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.
Contributor guide
Assessment
This issue has not been assessed yet.