Merge pull request #50 from garnaat/fix-48
Getting SNS sample working again
Showing
9 changed files
with
46 additions
and
153 deletions
... | @@ -81,7 +81,7 @@ class KinesisEventSource(EventSource): | ... | @@ -81,7 +81,7 @@ class KinesisEventSource(EventSource): |
81 | try: | 81 | try: |
82 | response = self._lambda.call( | 82 | response = self._lambda.call( |
83 | 'update_event_source_mapping', | 83 | 'update_event_source_mapping', |
84 | - FunctionName=function.name, | 84 | + UUID=self._get_uuid(function), |
85 | Enabled=self.enabled | 85 | Enabled=self.enabled |
86 | ) | 86 | ) |
87 | LOG.debug(response) | 87 | LOG.debug(response) |
... | @@ -242,6 +242,8 @@ class SNSEventSource(EventSource): | ... | @@ -242,6 +242,8 @@ class SNSEventSource(EventSource): |
242 | except Exception: | 242 | except Exception: |
243 | LOG.exception('Unable to add SNS event source') | 243 | LOG.exception('Unable to add SNS event source') |
244 | 244 | ||
245 | + enable = add | ||
246 | + | ||
245 | def update(self, function): | 247 | def update(self, function): |
246 | self.add(function) | 248 | self.add(function) |
247 | 249 | ||
... | @@ -257,6 +259,11 @@ class SNSEventSource(EventSource): | ... | @@ -257,6 +259,11 @@ class SNSEventSource(EventSource): |
257 | except Exception: | 259 | except Exception: |
258 | LOG.exception('Unable to remove event source %s', self.arn) | 260 | LOG.exception('Unable to remove event source %s', self.arn) |
259 | 261 | ||
262 | + disable = remove | ||
263 | + | ||
260 | def status(self, function): | 264 | def status(self, function): |
261 | LOG.debug('status for SNS notification for %s', function.name) | 265 | LOG.debug('status for SNS notification for %s', function.name) |
262 | - return self.exists(function) | 266 | + status = self.exists(function) |
267 | + if status: | ||
268 | + status['EventSourceArn'] = status['TopicArn'] | ||
269 | + return status | ... | ... |
... | @@ -122,8 +122,9 @@ def status(ctx): | ... | @@ -122,8 +122,9 @@ def status(ctx): |
122 | if status['event_sources']: | 122 | if status['event_sources']: |
123 | for event_source in status['event_sources']: | 123 | for event_source in status['event_sources']: |
124 | if event_source: | 124 | if event_source: |
125 | - line = ' {}: {}'.format( | 125 | + arn = event_source.get('EventSourceArn') |
126 | - event_source['EventSourceArn'], event_source['State']) | 126 | + state = event_source.get('State', 'Enabled') |
127 | + line = ' {}: {}'.format(arn, state) | ||
127 | click.echo(click.style(line, fg='green')) | 128 | click.echo(click.style(line, fg='green')) |
128 | else: | 129 | else: |
129 | click.echo(click.style(' None', fg='green')) | 130 | click.echo(click.style(' None', fg='green')) | ... | ... |
samples/sns/_src/sns.py
0 → 100644
samples/sns/config.yml
deleted
100644 → 0
1 | ---- | ||
2 | -# change profile and region to suit your needs | ||
3 | -profile: personal | ||
4 | -region: us-east-1 | ||
5 | -resources: resources.json | ||
6 | -iam: | ||
7 | - policy: | ||
8 | - description: A policy used with the Kappa SNS->DynamoDB example | ||
9 | - name: LambdaSNSSamplePolicy | ||
10 | - document: LambdaSNSSamplePolicy.json | ||
11 | - role: | ||
12 | - name: SNSSampleRole | ||
13 | - policy: LambdaSNSSamplePolicy | ||
14 | -lambda: | ||
15 | - name: SNSSample | ||
16 | - zipfile_name: SNSSample.zip | ||
17 | - description: Testing SNS -> DynamoDB Lambda handler | ||
18 | - path: messageStore.js | ||
19 | - handler: messageStore.handler | ||
20 | - runtime: nodejs | ||
21 | - memory_size: 128 | ||
22 | - timeout: 3 | ||
23 | - permissions: | ||
24 | - - | ||
25 | - statement_id: sns_invoke | ||
26 | - action: lambda:invokeFunction | ||
27 | - principal: sns.amazonaws.com | ||
28 | - # change this to refer to your own SNS topic | ||
29 | - source_arn: arn:aws:sns:us-east-1:084307701560:lambda_topic | ||
30 | - event_sources: | ||
31 | - - | ||
32 | - # change this to refer to your own SNS topic | ||
33 | - arn: arn:aws:sns:us-east-1:084307701560:lambda_topic | ||
34 | - test_data: input.json | ||
35 | - | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
samples/sns/dynamodb_table.json
deleted
100644 → 0
1 | -{ | ||
2 | - "TableName": "snslambda", | ||
3 | - "AttributeDefinitions": [ | ||
4 | - { | ||
5 | - "AttributeName": "SnsTopicArn", | ||
6 | - "AttributeType": "S" | ||
7 | - }, | ||
8 | - { | ||
9 | - "AttributeName": "SnsPublishTime", | ||
10 | - "AttributeType": "S" | ||
11 | - }, | ||
12 | - { | ||
13 | - "AttributeName": "SnsMessageId", | ||
14 | - "AttributeType": "S" | ||
15 | - } | ||
16 | - ], | ||
17 | - "KeySchema": [ | ||
18 | - { | ||
19 | - "AttributeName": "SnsTopicArn", | ||
20 | - "KeyType": "HASH" | ||
21 | - }, | ||
22 | - { | ||
23 | - "AttributeName": "SnsPublishTime", | ||
24 | - "KeyType": "RANGE" | ||
25 | - } | ||
26 | - ], | ||
27 | - "GlobalSecondaryIndexes": [ | ||
28 | - { | ||
29 | - "IndexName": "MesssageIndex", | ||
30 | - "KeySchema": [ | ||
31 | - { | ||
32 | - "AttributeName": "SnsMessageId", | ||
33 | - "KeyType": "HASH" | ||
34 | - } | ||
35 | - ], | ||
36 | - "Projection": { | ||
37 | - "ProjectionType": "ALL" | ||
38 | - }, | ||
39 | - "ProvisionedThroughput": { | ||
40 | - "ReadCapacityUnits": 5, | ||
41 | - "WriteCapacityUnits": 1 | ||
42 | - } | ||
43 | - } | ||
44 | - ], | ||
45 | - "ProvisionedThroughput": { | ||
46 | - "ReadCapacityUnits": 5, | ||
47 | - "WriteCapacityUnits": 5 | ||
48 | - } | ||
49 | -} |
samples/sns/kappa.yml.sample
0 → 100644
1 | +--- | ||
2 | +name: kappa-sns-sample | ||
3 | +environments: | ||
4 | + dev: | ||
5 | + # Change the profile and region to suit your application | ||
6 | + profile: <your profile name> | ||
7 | + region: <your region name> | ||
8 | + policy: | ||
9 | + resources: | ||
10 | + - arn: <arn to your SNS topic> | ||
11 | + actions: | ||
12 | + - "*" | ||
13 | + - arn: arn:aws:logs:*:*:* | ||
14 | + actions: | ||
15 | + - "*" | ||
16 | + event_sources: | ||
17 | + - arn: <arn to your SNS topic> | ||
18 | +lambda: | ||
19 | + description: A simple SNS example | ||
20 | + handler: sns.handler | ||
21 | + runtime: python2.7 | ||
22 | + memory_size: 128 | ||
23 | + timeout: 3 |
samples/sns/messageStore.js
deleted
100644 → 0
1 | -console.log('Loading event'); | ||
2 | -var aws = require('aws-sdk'); | ||
3 | -var ddb = new aws.DynamoDB({params: {TableName: 'snslambda'}}); | ||
4 | - | ||
5 | -exports.handler = function(event, context) { | ||
6 | - var SnsMessageId = event.Records[0].Sns.MessageId; | ||
7 | - var SnsPublishTime = event.Records[0].Sns.Timestamp; | ||
8 | - var SnsTopicArn = event.Records[0].Sns.TopicArn; | ||
9 | - var LambdaReceiveTime = new Date().toString(); | ||
10 | - var itemParams = {Item: {SnsTopicArn: {S: SnsTopicArn}, | ||
11 | - SnsPublishTime: {S: SnsPublishTime}, SnsMessageId: {S: SnsMessageId}, | ||
12 | - LambdaReceiveTime: {S: LambdaReceiveTime} }}; | ||
13 | - ddb.putItem(itemParams, function() { | ||
14 | - context.done(null,''); | ||
15 | - }); | ||
16 | -}; |
samples/sns/resources.json
deleted
100644 → 0
1 | -{ | ||
2 | - "AWSTemplateFormatVersion" : "2010-09-09", | ||
3 | - | ||
4 | - "Description" : "Creates the DynamoDB Table needed for the example", | ||
5 | - | ||
6 | - "Resources" : { | ||
7 | - "snslambda" : { | ||
8 | - "Type" : "AWS::DynamoDB::Table", | ||
9 | - "Properties" : { | ||
10 | - "AttributeDefinitions": [ | ||
11 | - { | ||
12 | - "AttributeName" : "SnsTopicArn", | ||
13 | - "AttributeType" : "S" | ||
14 | - }, | ||
15 | - { | ||
16 | - "AttributeName" : "SnsPublishTime", | ||
17 | - "AttributeType" : "S" | ||
18 | - } | ||
19 | - ], | ||
20 | - "KeySchema": [ | ||
21 | - { "AttributeName": "SnsTopicArn", "KeyType": "HASH" }, | ||
22 | - { "AttributeName": "SnsPublishTime", "KeyType": "RANGE" } | ||
23 | - ], | ||
24 | - "ProvisionedThroughput" : { | ||
25 | - "ReadCapacityUnits" : 5, | ||
26 | - "WriteCapacityUnits" : 5 | ||
27 | - } | ||
28 | - } | ||
29 | - } | ||
30 | - }, | ||
31 | - | ||
32 | - "Outputs" : { | ||
33 | - "TableName" : { | ||
34 | - "Value" : {"Ref" : "snslambda"}, | ||
35 | - "Description" : "Table name of the newly created DynamoDB table" | ||
36 | - } | ||
37 | - } | ||
38 | -} |
-
Please register or login to post a comment