Amazon SNS.
In our example we are going to use this to send an eMail to a specific address, but you can also use any other destinations supported by SNS like SMS or AWS ChatBot.
Unfortunately we will need to set up an SNS topic and a Lambda function in a dedicated AWS account in order to use these advanced notifications.
This means that we are “breaking” the concept of CodeCatalyst not requiring access to the AWS Console, but this is the only way that I found so far to be able to send additional notifications.
Ideally we would be setting up the SNS topic and the lambda function using CDK, but that increases the complexity of the workflow and of the setup and because of that I’m not including that in this blog post.
Please create a SNS topic following the AWS documentation through the console.
We assume the topic to be in “eu-central-1” and the name to be “codecatalyst-workflow-topic”.
After the topic has been set up, you will need to subscribe your eMail address to it.
You can follow this blog post to manually set up the lambda function through the AWS console, please ensure to give the Lambda functions permissions to use the SNS topic.
The required code using Python will look like this:
import boto3
sns = boto3.client('sns')
def lambda_handler(event, context):
try:
message = event['message']
topic_arn = 'arn:aws:sns:eu-central-1:<accountID>:codecatalyst-workflow-topic'
response = sns.publish(
TopicArn=topic_arn,
Message=message
)
print('Message sent to SNS topic:', response['MessageId'])
except Exception as e:
print('Error sending message: ', e)
Obviously the same can be achieved using Typscript, Go or any other supported function.
Please adjust the topic_arn to match the topic that you just created.
After creation this Lambda function will now have an ARN which should look similar to this:
arn:aws:lambda:eu-central-1:
We will need this ARN when setting up the notification in our Workflow.
Integrating this Lambda function into a workflow is easy:
NotifyMe:
Identifier: aws/lambda-invoke@v1
Environment:
Connections:
- Role: CodeCatalystPreviewDevelopmentAdministrator-wzkn0l
Name: "<connection>"
Name: development
Inputs:
Sources:
- WorkflowSource
Compute:
Type: Lambda
Configuration:
RequestPayload: '{"message":"branchName: ${WorkflowSource.BranchName}\nCommitID: ${WorkflowSource.CommitId}\nWorkflow-Name: NOT-AVAILABLE\nSTATUS: EXECUTED"}'
ContinueOnError: false
AWSRegion: eu-central-1
LogType: Tail
Function: arn:aws:lambda:eu-central-1:<accoutId>:function:send-sns-notification-python
As you can see, we are integrating an “aws/lambda-invoke@v1” action which then points to the lambda function that we just created.
In the “RequestPayload” we are passing a few information to the Lambda function which will then be passed to the SNS topic as part of the message.
This is how the message will look when received as eMail:
As you can see we are able to send notifications from CodeCatalyst to multiple targets, including eMail with this option.
What we are missing is - and I am not sure if thats possible or not - is all of the “metadata” of the workflow execution like:
In the documentation I was not able to find out the available environment variables about these information… If you do have any ideas on how to access this metadata, please let me know!