Skip to content

Commit

Permalink
Adding in fix for policy being updated everytime
Browse files Browse the repository at this point in the history
  • Loading branch information
StewartW committed May 27, 2021
1 parent 374105d commit d7ec3b0
Showing 1 changed file with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,49 @@
LOGGER = configure_logger(__name__)

class Notifications(core.Construct):
def __init__(self, scope: core.Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
def __init__(
self, scope: core.Construct, id: str, map_params: dict, **kwargs
): # pylint: disable=W0622
super().__init__(scope, id, **kwargs)
LOGGER.debug('Notification configuration required for %s', map_params['name'])
LOGGER.debug("Notification configuration required for %s", map_params["name"])
# pylint: disable=no-value-for-parameter
_slack_func = _lambda.Function.from_function_arn(
self,
'slack_lambda_function',
'arn:aws:lambda:{0}:{1}:function:SendSlackNotification'.format(
ADF_DEPLOYMENT_REGION,
ADF_DEPLOYMENT_ACCOUNT_ID
)
"slack_lambda_function",
"arn:aws:lambda:{0}:{1}:function:SendSlackNotification".format(
ADF_DEPLOYMENT_REGION, ADF_DEPLOYMENT_ACCOUNT_ID
),
)
_topic = _sns.Topic(self, 'PipelineTopic')
_topic = _sns.Topic(self, "PipelineTopic")
_statement = _iam.PolicyStatement(
actions=["sns:Publish"],
effect=_iam.Effect.ALLOW,
principals=[
_iam.ServicePrincipal(
'sns.amazonaws.com'
),
_iam.ServicePrincipal(
'codecommit.amazonaws.com'
),
_iam.ServicePrincipal(
'events.amazonaws.com'
)
_iam.ServicePrincipal("sns.amazonaws.com"),
_iam.ServicePrincipal("codecommit.amazonaws.com"),
_iam.ServicePrincipal("events.amazonaws.com"),
],
resources=["*"]
resources=["*"],
)
_topic.add_to_resource_policy(_statement)
_lambda.CfnPermission(
self,
'slack_notification_sns_permissions',
principal='sns.amazonaws.com',
action='lambda:InvokeFunction',
source_arn=_topic.topic_arn,
function_name='SendSlackNotification'
)
_endpoint = map_params.get('params', {}).get('notification_endpoint', '')
_endpoint = map_params.get("params", {}).get("notification_endpoint", "")
_sub = _sns.Subscription(
self,
'sns_subscription',
"sns_subscription",
topic=_topic,
endpoint=_endpoint if '@' in _endpoint else _slack_func.function_arn,
protocol=_sns.SubscriptionProtocol.EMAIL if '@' in _endpoint else _sns.SubscriptionProtocol.LAMBDA
endpoint=_endpoint if "@" in _endpoint else _slack_func.function_arn,
protocol=_sns.SubscriptionProtocol.EMAIL
if "@" in _endpoint
else _sns.SubscriptionProtocol.LAMBDA,
)
if '@' not in _endpoint:
_slack_func.add_event_source(
source=_event_sources.SnsEventSource(_topic)
if "@" not in _endpoint:
_lambda.CfnPermission(
self,
"slack_notification_sns_permissions",
principal="sns.amazonaws.com",
action="lambda:InvokeFunction",
source_arn=_topic.topic_arn,
function_name="SendSlackNotification",
)
_slack_func.add_event_source(source=_event_sources.SnsEventSource(_topic))
self.topic_arn = _topic.topic_arn

0 comments on commit d7ec3b0

Please sign in to comment.