walshe
September 15, 2017, 1:50am
1
I want to be able to react to dynamodb inserts for a certain table and basically post events to a SNS topic…
Do I need dynamodb to trigger a lambda first which would then have some logic to detect insert v update and subsequently post a sns event? OR is it possible to have dynamodb automatically put INSERT messages on SNS queue directly via some declarative config in serverless.yaml ?
buggy
September 15, 2017, 3:49am
2
Yes. You need to attach a Lambda to the DDB stream the write the message to SNS.
walshe
September 15, 2017, 2:11pm
3
I’m trying to stream dynamodb inserts to a lambda trigger but having some issues:
general config seems to be wrong
Is there a way I can get around having to hardcode the latest arn for the dynamodb stream ?
functions:
companyInfoByDateInsert:
handler: com.serverless.handlers.CompanyInfoByDateInsertHandler
events:
stream:
arn : arn:aws:dynamodb:us-east-1:xxxx:table/${self:provider.environment.companyInfoByDateDynamoDbTable}
batchSize: 100
enabled: true
resources:
Resources:
StockpickerDynamoDbTable:
Type: ‘AWS::DynamoDB::Table’
DeletionPolicy: Retain
Properties:
TableName: ${self:provider.environment.companyInfoByDateDynamoDbTable}
AttributeDefinitions:
-
AttributeName: date
AttributeType: S
-
AttributeName: ticker
AttributeType: S
KeySchema:
-
AttributeName: date
KeyType: HASH
-
AttributeName: ticker
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
StreamSpecification:
StreamViewType: NEW_IMAGE
buggy
September 16, 2017, 12:49pm
4
The streams documentation has an example https://serverless.com/framework/docs/providers/aws/events/streams/
- stream:
type: dynamodb
arn:
Fn::GetAtt:
- MyDynamoDbTable
- StreamArn
Also checkout the CloudFormation docs http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html
I believe the batchSize
and enabled
options you’re trying to use only apply to Kinesis streams.
walshe
September 16, 2017, 5:46pm
5
it just will not set up the trigger on my lambda - can you see anything obvious that is wrong here:
this time there is even nothing in the lambda trigger tab
service: groovy-stock-picker
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
provider:
name: aws
runtime: java8
timeout: 15
iamRoleStatements:
- Effect: "Allow"
Action:
- "lambda:InvokeFunction"
- "dynamodb:*"
Resource: "*"
companyInfoByDateDynamoDbTable: companyInfoByDate-${self:service}-${opt:stage,self:provider.stage}
companyReportsJobByDateDynamoDbTable: companyReportsJobByDate-${self:service}-${opt:stage,self:provider.stage}
package:
artifact: build/distributions/hello.zip
functions:
hello:
handler: com.serverless.handlers.Handler
getReportingCompaniesForDate:
handler: com.serverless.handlers.GetReportingCompaniesForDateHandler
companyInfoByDateInsert:
handler: com.serverless.handlers.CompanyInfoByDateInsertHandler
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt:
- ${self:provider.environment.companyInfoByDateDynamoDbTable}
- arn:aws:dynamodb:us-east-1:xxx:table/companyInfoByDate-groovy-stock-picker-dev/stream/2017-09-16T17:28:06.387
# you can add CloudFormation resource templates here
resources:
Resources:
StockpickerDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Delete
Properties:
TableName: ${self:provider.environment.companyInfoByDateDynamoDbTable}
AttributeDefinitions:
-
AttributeName: date
AttributeType: S
-
AttributeName: ticker
AttributeType: S
KeySchema:
-
AttributeName: date
KeyType: HASH
-
AttributeName: ticker
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
StreamSpecification:
StreamViewType: NEW_IMAGE