Skip to content

Commit

Permalink
Merge pull request #152 from mttfarmer/python-the-big-fan
Browse files Browse the repository at this point in the history
The Big Fan Python implementation
  • Loading branch information
cdk-patterns authored Jan 9, 2021
2 parents 15ef004 + 0076ba2 commit 0e52871
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 24 deletions.
11 changes: 0 additions & 11 deletions the-big-fan/python/lambda_fns/subscribe/anyOtherStatus.js

This file was deleted.

13 changes: 13 additions & 0 deletions the-big-fan/python/lambda_fns/subscribe/anyOtherStatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json
import logging

def handler(event, context):
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.info("request: " + json.dumps(event))

records = event["Records"]

for record in records:
payload = record["body"]
logger.info("received message " + payload)
11 changes: 0 additions & 11 deletions the-big-fan/python/lambda_fns/subscribe/createdStatus.js

This file was deleted.

13 changes: 13 additions & 0 deletions the-big-fan/python/lambda_fns/subscribe/createdStatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json
import logging

def handler(event, context):
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.info("request: " + json.dumps(event))

records = event["Records"]

for record in records:
payload = record["body"]
logger.info("received message " + payload)
Empty file.
Empty file.
49 changes: 49 additions & 0 deletions the-big-fan/python/tests/unit/test_the_big_fan_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import json
import pytest

from aws_cdk import core
from the_big_fan.the_big_fan_stack import TheBigFanStack

#TODO: replace these with aws-cdk/assert(or similar testing framework) if a python implementation is released
def get_template():
app = core.App()
TheBigFanStack(app, "MyTestStack")
return json.dumps(app.synth().get_stack("MyTestStack").template)


def test_sns_topic_created():
assert("The Big Fan CDK Pattern Topic" in get_template())


def test_statusCreated_subscriber_sqs_created():
print(get_template())
assert("BigFanTopicStatusCreatedSubscriberQueue" in get_template())

def test_anyOtherStatus_subscriber_sqs_created():
assert("BigFanTopicAnyOtherStatusSubscriberQueue" in get_template())

def test_statusCreated_sns_message_subscription():
assert('FilterPolicy": {"status": ["created"]}' in get_template())

def test_anyOtherStatus_sns_message_subscription():
assert('"FilterPolicy": {"status": [{"anything-but": ["created"]}]}' in get_template())

def test_sqs_receiveMessage_iam_policy_created():
assert(('"PolicyDocument": {'
'"Statement": ['
'{"Action": ['
'"sqs:ReceiveMessage", '
'"sqs:ChangeMessageVisibility", '
'"sqs:GetQueueUrl", '
'"sqs:DeleteMessage", '
'"sqs:GetQueueAttributes"], '
'"Effect": "Allow"') in get_template())

def test_createdStatus_sqs_subscriber_lambda_created():
assert('"Handler": "createdStatus.handler"' in get_template())

def test_anyOtherStatus_sqs_subscriber_lambda_created():
assert('"Handler": "anyOtherStatus.handler"' in get_template())

def test_api_gateway_sendEvent_created():
assert('"PathPart": "SendEvent"' in get_template())
4 changes: 2 additions & 2 deletions the-big-fan/python/the_big_fan/the_big_fan_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:

# Created status queue lambda
sqs_created_status_subscriber = _lambda.Function(self, "SQSCreatedStatusSubscribeLambdaHandler",
runtime=_lambda.Runtime.NODEJS_12_X,
runtime=_lambda.Runtime.PYTHON_3_8,
handler="createdStatus.handler",
code=_lambda.Code.from_asset("lambda_fns/subscribe")
)
Expand All @@ -64,7 +64,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:

# Any other status queue lambda
sqs_other_status_subscriber = _lambda.Function(self, "SQSAnyOtherStatusSubscribeLambdaHandler",
runtime=_lambda.Runtime.NODEJS_12_X,
runtime=_lambda.Runtime.PYTHON_3_8,
handler="anyOtherStatus.handler",
code=_lambda.Code.from_asset("lambda_fns/subscribe")
)
Expand Down

0 comments on commit 0e52871

Please sign in to comment.