<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tish H. on Medium]]></title>
        <description><![CDATA[Stories by Tish H. on Medium]]></description>
        <link>https://medium.com/@techytish?source=rss-9da100b017f5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Tish H. on Medium</title>
            <link>https://medium.com/@techytish?source=rss-9da100b017f5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 12:09:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@techytish/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Automating AWS Lambda Deprecation Checks with Azure DevOps]]></title>
            <link>https://medium.com/@techytish/automating-aws-lambda-deprecation-checks-with-azure-devops-f98dfcb1c9b6?source=rss-9da100b017f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f98dfcb1c9b6</guid>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Tish H.]]></dc:creator>
            <pubDate>Sun, 19 Mar 2023 19:00:07 GMT</pubDate>
            <atom:updated>2023-03-25T10:49:44.419Z</atom:updated>
            <content:encoded><![CDATA[<h3>🚀 Overview</h3><p>Are you looking for a way to automate checking for deprecated runtime versions in your AWS Lambda functions?</p><p>Look no further than this project! Using Python scripts and the AWS CLI, you can easily search through your AWS accounts and list all Lambda functions, as well as check for deprecated runtime versions.</p><p>And with Azure DevOps pipelines, you can automate this process to save time and reduce the risk of missing critical updates.</p><h3>📌 Prerequisites</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*zQIIKjHXPfyjAs3LSnYu2g.png" /><figcaption>Technologies used: AWS, Python, Git, Azure DevOps Pipelines</figcaption></figure><p>Before you get started with this project, make sure you have the following prerequisites:</p><ul><li>An AWS account with Lambda functions</li><li>An Azure DevOps account with pipelines</li><li>Git installed on your local machine</li><li>Python 3.x installed on your local machine</li></ul><h3>💻 Installation</h3><blockquote><strong>Clone the repository</strong></blockquote><pre>git clone https://github.com/TechyTish/aws-real-world-projects.git</pre><blockquote><strong>Navigate to the </strong><strong><em>aws-lambda-deprecation-checker</em> directory:</strong></blockquote><pre>cd aws-real-world-projects/aws-lambda-deprecation-checker</pre><p><strong>Below ⬇️ is an overview of the files in this repository:</strong></p><ul><li><strong>aws_lambda.yml</strong>: This file contains the Azure DevOps pipeline configuration in YAML format. It defines the different stages of the pipeline, the tasks to be executed in each stage, and the variables that are required to run the pipeline. It also references the Python scripts that will be used to check for deprecated runtime versions in AWS Lambda functions.</li><li><strong>aws_lambda.py</strong>: This file contains the Python script that is executed as part of the pipeline. It uses the AWS CLI to search through AWS accounts and list all Lambda functions. It also checks for deprecated runtime versions and outputs the results in a format that is compatible with Azure DevOps test results.</li><li><strong>requirements.txt</strong>: This file lists the Python packages that are required to run the aws_lambda.py script. These packages are installed automatically when the pipeline is run.</li></ul><blockquote><strong>Create a virtual environment:</strong></blockquote><pre>python -m venv env<br>source env/bin/activate  # for Linux/Mac<br>env\Scripts\activate  # for Windows</pre><blockquote><strong>Install the required packages:</strong></blockquote><pre>pip install -r requirements.txt</pre><blockquote><strong>Set up the AWS CLI on your local machine:</strong></blockquote><ul><li>Follow the instructions in the AWS documentation to install and configure the AWS CLI: <a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html">https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html</a></li><li>Make sure that you have permissions to access the Lambda functions in your AWS account.</li></ul><blockquote><strong>Create an AWS IAM user with programmatic access and the necessary permissions:</strong></blockquote><ul><li>In the AWS Management Console, go to “Services” &gt; “IAM”.</li><li>Click 🖱 “Users” &gt; “Add User”.</li><li>Give the user a name and select “Programmatic access” as the access type.</li><li>Attach the “AWSLambdaReadOnlyAccess” and “CloudWatchLogsReadOnlyAccess” policies to the user.</li><li>Click 🖱 “Create User” and note down the access key ID and secret access key.</li></ul><blockquote><strong>Set up the Azure DevOps pipeline:</strong></blockquote><p>Now that we have our AWS credentials set up and ready, it’s time to set up our pipeline on Azure DevOps.</p><ul><li>In your Azure DevOps project, go to “Pipelines” &gt; “Library”.</li><li>Click 🖱 on “New Variable Group” and give it a name, like “AWS Credentials”.</li><li>In the “Variables” tab, add the following variables:</li><li>AWS_ACCESS_KEY_ID: your AWS access key ID</li><li>AWS_SECRET_ACCESS_KEY: your AWS secret access key</li><li>AWS_DEFAULT_REGION: the AWS region you want to use, like &quot;us-east-1&quot;</li><li>Click 🖱 “Save” to create the variable group.</li><li>In your pipeline YAML file, add a variables section at the top, like this:</li></ul><pre>variables:<br>  - group: AWS Credentials</pre><p>After setting up the pipeline YAML, we need to specify the steps that the pipeline should follow. In this case, we need to run the Python scripts that search through AWS accounts and list all Lambda functions, as well as checking for deprecated runtime versions.</p><blockquote><strong>Here is an example of a YAML file for our pipeline with the necessary steps:</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f4714971959f9684a357d4549d8309b/href">https://medium.com/media/4f4714971959f9684a357d4549d8309b/href</a></iframe><p>This YAML file defines the following steps:</p><ol><li>Use Python version 3.x</li><li>Install Python dependencies from requirements.txt</li><li>Run aws_lambda.py script</li><li>Publish test results in JUnit format</li><li>Publish pipeline artifact</li></ol><blockquote><strong>Here is what the python script may look like:</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78478310cc109c5af712cf1344c3e801/href">https://medium.com/media/78478310cc109c5af712cf1344c3e801/href</a></iframe><p>Once we have set up the pipeline YAML and defined the necessary steps, we can run the pipeline by clicking 🖱 “Save and run”.</p><h3>👀 Viewing results</h3><p>After the pipeline has finished running, we can view the results in the “Tests” and “Artifacts” tabs in the pipeline summary.</p><p>In the “Tests” tab, we can see the test results for the pipeline. In our case, the test results will show whether each Lambda function in our AWS account is using a deprecated runtime version or not.</p><p>In the “Artifacts” tab, we can see the pipeline artifact that was published. This artifact contains a CSV file with the list of Lambda functions and their runtime versions, as well as a log file with the output of the Python scripts.</p><blockquote><strong>Here is an example of what the CSV file might look like:</strong></blockquote><pre>Function Name,Runtime Version,Deprecated<br>my-lambda-function,python2.7,Yes<br>another-lambda-function,nodejs6.10,Yes</pre><blockquote><strong>And here is an example of what the log file might look like:</strong></blockquote><pre>Listing Lambda functions...<br>Found 2 functions in account: my-lambda-function, another-lambda-function<br>Checking runtime versions...<br>my-lambda-function is using deprecated runtime version python2.7<br>another-lambda-function is using deprecated runtime version nodejs6.10</pre><p>With these results, we can take action to update our Lambda functions to use non-deprecated runtime versions, ensuring that our functions remain secure and up-to-date.</p><h3>Source Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*19fHybZxAoTMpy8A.png" /><figcaption>GitHub profile page</figcaption></figure><p>➡️ Visit my <a href="https://github.com/TechyTish/aws-real-world-projects/tree/aws-lambda-deprecation-checker"><strong>GitHub</strong></a> repository for the source code for this service and fork the repo. Happy coding! 💻</p><p>😃 I will be adding more projects overtime and you will be able to access them via the branch name.</p><h3>💭 Thank you for reading!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f98dfcb1c9b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating an Alert Notification in Microsoft Teams for AWS CloudWatch Alarms]]></title>
            <link>https://medium.com/@techytish/creating-an-alert-notification-in-microsoft-teams-for-aws-cloudwatch-alarms-d21ffd28e90e?source=rss-9da100b017f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d21ffd28e90e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[microsoft-teams]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[notifications]]></category>
            <dc:creator><![CDATA[Tish H.]]></dc:creator>
            <pubDate>Sun, 12 Mar 2023 17:07:02 GMT</pubDate>
            <atom:updated>2023-03-25T10:49:02.355Z</atom:updated>
            <content:encoded><![CDATA[<p>AWS CloudWatch is a monitoring and management service that provides real-time monitoring of various AWS resources and applications. CloudWatch provides alarm notifications for specific metric thresholds that can be configured using Amazon SNS.</p><p>This tutorial will guide you through the process of creating an AWS Lambda function in Python 3.9 to send notifications to a Microsoft Teams channel using SNS when a CloudWatch alarm is triggered.</p><p>We will use Terraform to create the AWS resources, which includes the Lambda function, SNS topic, and IAM roles.</p><p>Requirements:</p><ul><li>AWS account</li><li>Terraform</li><li>Microsoft Teams account</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*42OuwuPj0S7dtlYfmwbSPA.png" /></figure><h3>1. Create a Microsoft Teams Webhook</h3><p>To send notifications to a Microsoft Teams channel, we need to create an incoming webhook in Microsoft Teams. Follow these steps to create a webhook:</p><ol><li>Navigate to the Teams channel where you want to send notifications</li><li>Click 🖱 on the three dots (<strong>ellipsis</strong>) next to the channel name and select “Connectors”</li><li>Search for “Incoming Webhook” and click 🖱 “<strong>Add</strong>”</li><li>Enter a name for the webhook and click 🖱 “<strong>Create</strong>”</li><li><strong>Copy</strong> the webhook URL</li></ol><h3>2. Create the SNS Topic</h3><p>We will use SNS to send notifications to the Lambda function, which will then send them to the Teams channel. Follow these steps to create an SNS topic:</p><ol><li>Create a file named main.tf in your Terraform directory</li><li>Add the following code to the file:</li></ol><pre># Set AWS provider to the specified region<br>provider &quot;aws&quot; {<br>  region = var.region<br>}<br><br># Create an SNS topic for CloudWatch alarms<br>resource &quot;aws_sns_topic&quot; &quot;cloudwatch_alarm_topic&quot; {<br>  name = var.sns_topic_name<br>}</pre><h3>3. Create the Lambda Function</h3><p>Next, we will create the Lambda function using Python 3.9 that will send the notifications to the Teams channel. Follow these steps to create the Lambda function:</p><ol><li>Create a file named lambda_function.py in your Terraform directory</li><li>Add the following code to the file:</li></ol><pre>import json   # Importing json library for parsing JSON data<br>import requests   # Importing requests library for sending HTTP requests<br>import os   # Importing os library for accessing environment variables<br><br>def lambda_handler(event, context):<br>    # Accessing the message from the SNS event passed as input to the Lambda function<br>    message = event[&#39;Records&#39;][0][&#39;Sns&#39;][&#39;Message&#39;]<br>    <br>    # Parsing the JSON message to extract various details about the CloudWatch alarm triggered<br>    message = event[&#39;Records&#39;][0][&#39;Sns&#39;][&#39;Message&#39;]<br>    alarm_name = json.loads(message)[&#39;AlarmName&#39;]<br>    alarm_desc = json.loads(message)[&#39;AlarmDescription&#39;]<br>    new_state = json.loads(message)[&#39;NewStateValue&#39;]<br>    alarm_time = json.loads(message)[&#39;StateChangeTime&#39;]<br>    instance_id = json.loads(message)[&#39;Trigger&#39;][&#39;Dimensions&#39;][0][&#39;value&#39;]<br>    region = json.loads(message)[&#39;Region&#39;]<br>    account_id = context.invoked_function_arn.split(&#39;:&#39;)[4]<br>    <br>    # Create url link to view alarm<br>    alarm_url = f&quot;https://console.aws.amazon.com/cloudwatch/home?region={region}#s=Alarms&amp;alarm={alarm_name}&quot;<br>    <br>    # Setting the theme color for the Teams message based on the new state of the alarm<br>     if new_state == &quot;ALARM&quot;:<br>        colour = &quot;FF0000&quot;<br>    elif new_state == &quot;OK&quot;:<br>        colour = &quot;00FF00&quot;<br>    else:<br>        colour = &quot;0000FF&quot;<br>    <br>    # Constructing the Teams message payload for an alarm<br>    message_card = {<br>        &quot;@type&quot;: &quot;MessageCard&quot;,<br>        &quot;@context&quot;: &quot;http://schema.org/extensions&quot;,<br>        &quot;themeColor&quot;: color,<br>        &quot;title&quot;: f&quot;{alarm_name} {new_state} on {instance_id}&quot;,<br>        &quot;text&quot;: f&quot;Alarm description: {alarm_desc}\nCurrent state: {new_state}\nTriggered time: {alarm_time}&quot;,<br>        &quot;potentialAction&quot;: [<br>            {<br>                &quot;@type&quot;: &quot;OpenUri&quot;,<br>                &quot;name&quot;: &quot;View Alarm&quot;,<br>                &quot;targets&quot;: [<br>                    {<br>                        &quot;os&quot;: &quot;default&quot;,<br>                        &quot;uri&quot;: alarm_url<br>                    }<br>                ]<br>            }<br>        ]<br>    }<br>    <br>    # Sending the Teams message to the specified webhook URL<br>    webhook_url = os.environ[&#39;TEAMS_WEBHOOK_URL&#39;]<br>    headers = {<br>      &#39;Content-Type&#39;: &#39;application/json&#39;<br>    }<br>    response = requests.post(webhook_url, json=message_card, headers=headers)<br>    print(response.text)</pre><p>This code defines a Lambda function that will be triggered by SNS when a CloudWatch alarm is triggered. The function extracts information from the alarm notification, constructs a message to send to Microsoft Teams, and then sends that message using another Lambda function.</p><p>We also include an url so that when the notification is sent to Microsoft teams it allows us to click the link to view the alarm in the AWS console.</p><h3>4. Create the CloudWatch alarm metric</h3><ol><li>Open the main.tf file named in your terraform directory and add the following code:</li></ol><pre># Create a CloudWatch metric alarm for CPU utilization<br>resource &quot;aws_cloudwatch_metric_alarm&quot; &quot;alarm&quot; {<br>  alarm_name          = var.alarm_name<br>  comparison_operator = var.cloudwatch_metric_operator<br>  evaluation_periods  = var.cloudwatch_metric_evaluation_periods<br>  metric_name         = var.cloudwatch_metric_name<br>  namespace           = var.cloudwatch_metric_namespace<br>  period              = var.cloudwatch_metric_period<br>  statistic           = &quot;Average&quot;<br>  threshold           = var.cloudwatch_metric_threshold<br>  alarm_description   = var.cloudwatch_metric_description<br>  alarm_actions       = [aws_sns_topic.sns_topic.arn]<br>  dimensions          = {<br>    &quot;${var.cloudwatch_metric_dimension_name}&quot; = var.cloudwatch_metric_dimension_value<br>  }<br>}</pre><p>In the above code, we define an CloudWatch alarm, for one for EC2 instance. The alarm is triggered based on metrics specified.</p><p>The key properties of the alarms are:</p><ul><li>alarm_name: The name of the alarm that will be created in CloudWatch.</li><li>comparison_operator: The operator that will be used to compare the metric data to the threshold. In this case, we use GreaterThanThreshold to trigger the alarm when the metric value is greater than the threshold.</li><li>evaluation_periods: The number of consecutive periods that the metric value must exceed the threshold before the alarm is triggered.</li><li>metric_name: The name of the metric that will be monitored.</li><li>namespace: The namespace of the metric that will be monitored.</li><li>period: The period of time, in seconds, over which the metric value will be evaluated.</li><li>statistic: The statistic that will be used to evaluate the metric value. In this case, we use Average to calculate the average value of the metric over the evaluation period.</li><li>threshold: The value that the metric must exceed in order to trigger the alarm.</li><li>actions_enabled: Whether or not to enable actions for the alarm. In this case, we set it to true to allow the alarm to send notifications.</li><li>alarm_description: A description of the alarm.</li><li>ok_actions: The actions to take when the alarm transitions to the OK state.</li><li>alarm_actions: The actions to take when the alarm transitions to the ALARM state.</li></ul><p>In the alarm, we set the ok_actions and alarm_actions properties to the ARN of the SNS topic that we created earlier. This ensures that notifications will be sent to the topic when the alarm is triggered.</p><p>We have used variables so this can be defined for each terraform workspace/directory that will be using the configuration. It also means that you’re able to change the values accordingly.</p><h3>5. Add the lambda function in Terraform</h3><ol><li>Open the main.tf file named in your terraform directory and add the following code:</li></ol><pre>resource &quot;aws_lambda_function&quot; &quot;sns_to_teams&quot; {<br>  filename      = &quot;lambda_function.zip&quot;<br>  function_name = var.lambda_name<br>  role          = aws_iam_role.lambda_execution.arn<br>  handler       = var.lambda_handler_name<br>  runtime       = &quot;python3.9&quot;<br>  timeout       = &quot;60&quot;<br>  runtime       = var.lambda_runtime<br>  timeout       = var.lambda_timeout<br>  memory_size   = var.lambda_memory_size<br><br>  # Set environment variables for the Lambda function<br>  environment {<br>    variables = {<br>      MS_TEAMS_WEBHOOK_URL = var.ms_teams_webhook_url<br>    }<br>  }<br><br>  # Depend on the SNS topic and Lambda execution policy<br>  depends_on = [<br>    aws_sns_topic.cloudwatch_alarm_topic,<br>    aws_iam_role_policy.lambda_execution_policy,<br>  ]<br>}</pre><p>This Terraform code defines an AWS Lambda function resource that uses the IAM role we created earlier, and specifies the lambda_function.py file as the source code for the function. It also sets the function&#39;s environment variable to the Microsoft Teams webhook URL that we created earlier.</p><h3>6. Add Subscription to SNS Topic</h3><p>We need to add a subscription to the SNS topic we added in step 1. This will allow notifications to be sent to Microsoft Teams.</p><ol><li>Open the main.tf file named in your terraform directory and add the following code:</li></ol><pre># Create an SNS topic subscription for CloudWatch alarms<br>resource &quot;aws_sns_topic_subscription&quot; &quot;teams_notifications_subscription&quot; {<br>  topic_arn = aws_sns_topic.cloudwatch_alarm_topic.arn<br>  protocol  = &quot;https&quot;<br>  endpoint  = var.teams_webhook_url<br>}</pre><p>In the above code, we’re creating an SNS subscription that uses HTTPS as the protocol and the webhook URL for the Microsoft Teams channel as the endpoint. Note that we’re using a variable named teams_webhook_url. You&#39;ll need to define this variable in a file named variables.tf.</p><h3>7. Configure the Lambda Function</h3><p>Now that we have the SNS topic and subscription, we need to configure the Lambda function to use them.</p><ol><li>Open the main.tf file named in your terraform directory and add the following code:</li></ol><pre># Create a cloudwatch event target<br>resource &quot;aws_cloudwatch_event_target&quot; &quot;teams_notifications&quot; {<br>  rule      = aws_cloudwatch_event_rule.cloudwatch_rule.name<br>  target_id = &quot;teams_notifications&quot;<br>  arn       = aws_lambda_function.teams_notifications.arn<br>}<br><br># Create permissions for the lambda<br>resource &quot;aws_lambda_permission&quot; &quot;allow_cloudwatch_to_invoke_teams_notifications_lambda&quot; {<br>  statement_id  = &quot;AllowExecutionFromCloudWatch&quot;<br>  action        = &quot;lambda:InvokeFunction&quot;<br>  function_name = aws_lambda_function.send_notification_to_teams.function_name<br>  principal     = &quot;events.amazonaws.com&quot;<br>  source_arn    = aws_cloudwatch_event_rule.cloudwatch_rule.arn<br>}</pre><p>In the above code, we’re creating a CloudWatch event target that uses the Lambda function as the target. We’re also creating a Lambda permission that allows CloudWatch to invoke the Lambda function. ❗ ️Note that we’re using the same name for the target ID (send_notification_to_teams) as we used for the SNS subscription.</p><h3>8. Create the variables Terraform file</h3><p>This files define the inputs of the Terraform module, and allow for customisation and configuration of the resources being created.</p><ol><li>Create a new file named variables.tf in your terraform directory and add the following code:</li></ol><pre>Now that we have the SNS topic and subscription, we need to configure the Lambda function to use them.<br></pre><h3>9. Create the outputs Terraform file</h3><p>This defines the outputs of the Terraform module, and allow for you to see the outputs of the resources created.</p><ol><li>Create a new file named outputs.tf in your terraform directory and add the following code:</li></ol><pre>output &quot;sns_topic_arn&quot; {<br>  value = aws_sns_topic.sns_topic.arn<br>}<br><br>output &quot;lambda_function_name&quot; {<br>  value = aws_lambda_function.lambda_function.function_name<br>}<br><br>output &quot;lambda_function_arn&quot; {<br>  value = aws_lambda_function.lambda_function.arn<br>}<br><br>output &quot;lambda_function_role&quot; {<br>  value = aws_iam_role.lambda_function_role.arn<br>}<br><br>output &quot;cloudwatch_metric_alarm&quot; {<br>  value = aws_cloudwatch_metric_alarm.alarm.arn<br>}</pre><h3>10. Deploy the terraform resources</h3><p>We now have a complete lambda function written in Python and configured our resources ready for deployment in Terraform.</p><p>Let’s go ahead and deploy the resources:</p><ol><li>In your terraform directory run terraform init</li><li>Then run terraform plan</li><li>Check the plan is configured correctly</li><li>Then run terraform apply</li></ol><p>Your resources should now be deployed.</p><h3>11. Test the Lambda Function in AWS Console</h3><p>This is optional, and ideal for existing alarms where you need to just create a Lambda Function (perhaps outside of terraform) and test the notification appears in teams.</p><ol><li>Create your lambda function</li><li>Add your python code</li><li>Add your environment variables in the lambda configuration for the teams_webhook_url variable.</li><li>Click on the TEST button above the lambda code</li><li>Add the following .json code and click 🖱 save &gt; then click 🖱 TEST</li></ol><pre>{<br>  &quot;version&quot;: &quot;0&quot;,<br>  &quot;id&quot;: &quot;12345678-1234-1234-1234-123456789012&quot;,<br>  &quot;detail-type&quot;: &quot;CloudWatch Alarm State Change&quot;,<br>  &quot;source&quot;: &quot;aws.cloudwatch&quot;,<br>  &quot;account&quot;: &quot;123456789012&quot;,<br>  &quot;time&quot;: &quot;2023-03-01T12:00:00Z&quot;,<br>  &quot;region&quot;: &quot;us-east-1&quot;,<br>  &quot;resources&quot;: [<br>    &quot;arn:aws:cloudwatch:us-east-1:123456789012:alarm:my-alarm&quot;<br>  ],<br>  &quot;detail&quot;: {<br>    &quot;alarmName&quot;: &quot;CPU Utilization&quot;,<br>    &quot;alarmDescription&quot;: &quot;The CPU utilization of the EC2 instance has exceeded 90% for the last 5 minutes.&quot;,<br>    &quot;awsAccountId&quot;: &quot;123456789012&quot;,<br>    &quot;newStateValue&quot;: &quot;ALARM&quot;,<br>    &quot;newStateReason&quot;: &quot;Threshold Crossed: 1 datapoint [99.0 (28/02/23 12:45:00)] was greater than or equal to the threshold (90.0).&quot;,<br>    &quot;stateChangeTime&quot;: &quot;2023-03-01T12:00:00.000+0000&quot;,<br>    &quot;region&quot;: &quot;us-east-1&quot;,<br>    &quot;oldStateValue&quot;: &quot;OK&quot;,<br>    &quot;trigger&quot;: {<br>      &quot;metricName&quot;: &quot;CPUUtilization&quot;,<br>      &quot;namespace&quot;: &quot;AWS/EC2&quot;,<br>      &quot;dimensions&quot;: [<br>        {<br>          &quot;name&quot;: &quot;InstanceId&quot;,<br>          &quot;value&quot;: &quot;i-0123456789abcdef0&quot;<br>        }<br>      ],<br>      &quot;period&quot;: 300,<br>      &quot;evaluationPeriods&quot;: 1,<br>      &quot;comparisonOperator&quot;: &quot;GreaterThanOrEqualToThreshold&quot;,<br>      &quot;threshold&quot;: 90.0,<br>      &quot;datapointsToAlarm&quot;: 1,<br>      &quot;treatMissingData&quot;: &quot;- TreatMissingData: missing&quot;,<br>      &quot;evaluateLowSampleCountPercentile&quot;: &quot;&quot;<br>    }<br>  }<br>}</pre><p>The notification should now appear in your microsoft teams team/channel where the webhook connector has been defined.</p><h3>12. Test the Integration</h3><p>Now that everything is set up, we can test the integration by triggering a CloudWatch alarm. To do this, follow these steps:</p><ol><li>Open the CloudWatch console and navigate to the Alarms section.</li><li>Select an existing alarm or create a new one.</li><li>Click the Actions button and select “Create a new SNS topic”.</li><li>Select the SNS topic we created earlier (teams_notifications) and click Create Topic.</li><li>Click the Create Alarm button to create the alarm.</li></ol><p>This will trigger the alarm, which in turn will send a notification to the SNS topic. The Lambda function will then be triggered, which will send the notification to the Microsoft Teams channel.</p><p>To verify that the notification was sent to the channel, open the channel in Microsoft Teams and look for the message. The message should contain information about the EC2 instance and the type of alarm that was triggered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BqBZTjZggCeBIAWD_Gp8Gw.png" /><figcaption>Screenshot of an CloudWatch alarm triggered via SNS topic and Lambda Function in AWS</figcaption></figure><h3>Conclusion</h3><p>Notifications are a crucial part of any DevOps workflow, and Microsoft Teams is a popular collaboration platform for teams. By integrating Microsoft Teams with AWS services such as CloudWatch, you can streamline your workflow and respond to incidents quickly and efficiently.</p><p>In this article, we have walked through the process of setting up a notification in Microsoft Teams for a CloudWatch alarm using SNS and a Lambda function written in Python 3.9. We used Terraform to deploy the necessary AWS resources and demonstrated how to test the notification using a simulated CPU overload on an EC2 instance.</p><p>I hope this article has been helpful in showing you how to set up a notification in Microsoft Teams for a CloudWatch alarm using AWS services.</p><h3>Source Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pHO5XbcFcJD4CMyg.png" /><figcaption>GitHub profile page</figcaption></figure><p>➡️ Visit my <a href="https://github.com/TechyTish/aws-real-world-projects/tree/aws-cloudwatch-alarms-to-microsoft-teams"><strong>GitHub</strong></a> repository for the source code for this service and fork the repo. Happy coding! 💻</p><p>😃 I will be adding more services overtime and you will be able to access them via the branch name.</p><h3>💭 Thank you for reading!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d21ffd28e90e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Pingdom & Microsoft Teams (Part 2/2)]]></title>
            <link>https://medium.com/@techytish/integrate-pingdom-microsoft-teams-part-2-2-25119873825f?source=rss-9da100b017f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/25119873825f</guid>
            <category><![CDATA[postman]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[microsoft-teams]]></category>
            <dc:creator><![CDATA[Tish H.]]></dc:creator>
            <pubDate>Sun, 05 Mar 2023 23:51:24 GMT</pubDate>
            <atom:updated>2023-03-19T15:41:43.455Z</atom:updated>
            <content:encoded><![CDATA[<p>❗️Hi and welcome back 👋, this is <strong>part 2/2</strong> of the solution.</p><blockquote><em>🔥 ✅</em> If you haven’t already, read ▶️ <a href="https://medium.com/@techytish/integrate-pingdom-microsoft-teams-part-1-2-d0ef36e3f81c"><strong>part 1/2</strong></a> which goes over:</blockquote><ul><li><strong>current problem</strong>, defining the issue between Pingdom and Microsoft Teams</li><li><strong>solution overview</strong>, defining how the issue is being solved</li><li><strong>pre-requisite technologies</strong>, listing the tools &amp; services you need to have access to</li><li><strong>costing</strong>, how much will the aws lambda &amp; aws api gateway cost?</li></ul><h3>Part 2/2 Summary</h3><p>In this article, I will go over the following:</p><ul><li><strong>implementation</strong>, build and deploy the solution</li><li><strong>testing</strong> the solution works</li><li><strong>along</strong> with some gotcha’s, troubleshooting guidance</li><li><strong>security</strong>, my tips on improvements</li></ul><h3>Implementation</h3><p>Now that you have all the pre-requisites, lets begin with the step by step process for creating &amp; sending the notifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W60V1Xehj4D3cGB1" /><figcaption>Photo by <a href="https://unsplash.com/@ralexnder?utm_source=medium&amp;utm_medium=referral">Alex Chumak</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>1. Create a Pingdom Check</h4><p>We will create a check in Pingdom for Google UK, replace the hostname with one of your choosing.</p><ol><li>Sign into<strong> </strong><a href="https://my.pingdom.com/app/3/home"><strong>https://my.pingdom.com/app/3/home</strong></a></li><li>On the Menu on the ◀️ , go to <strong>Synthetics</strong> ▶️ <strong>Uptime</strong></li><li>On the <strong>Uptime</strong> page, click 🖱 on <strong>Add New</strong></li><li>Enter the <strong>Check details</strong> as:</li></ol><blockquote><strong>Name of Check</strong>: check_google</blockquote><blockquote><strong>Check Interval</strong>: 5 Minutes</blockquote><blockquote><strong>URL/IP</strong>: http:// &amp; <a href="https://medium.com/www.google.com/">www.google.com</a></blockquote><p>All other settings leave as default, we will come back at a later stage to add the endpoint url (restful api) to the check.</p><p>❗️Depending on the url you’re checking, consider whether it should be <strong>http:// </strong>or <a href="https://,/"><strong>https://</strong>,</a> one sends encrypted data the other doesn’t. For Google checks, we don’t need to send any encrypt any data.</p><ul><li>You can view a more detailed example <a href="https://documentation.solarwinds.com/en/success_center/pingdom/content/topics/how-to-set-up-a-http-s-check.htm"><strong>here</strong></a> for setting an Uptime check</li></ul><p>❗️You should also check the optional settings, in case there is any additional requirements you need to have, remember this request is being sent to the API Gateway not directly to Microsoft Teams!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xFaM17yDwE5Mu0xDb1liwQ.png" /><figcaption>Screenshot of creating a check in Pingdom for google.com</figcaption></figure><h4>2. Setup the Microsoft Teams Incoming Webhook</h4><p>The whole point of this is to receive the notifications right, so we need to create the incoming webhook on Teams for a team or channel of your choosing.</p><ol><li>Create your team or channel, in this case I have created a <strong>Team</strong> for testing purposes and I’ve used the default channel <strong>General</strong>. You can find instructions <a href="https://support.microsoft.com/en-us/office/create-a-team-from-scratch-174adf5f-846b-4780-b765-de1a0a737e2b">here</a>.</li><li>Right <strong>click</strong> 🖱 on the team/channel depending on where you’re sending it to and click 🖱 on ▶️ <strong>Connectors</strong></li><li>In the list of connectors, find and click 🖱 <strong>ADD</strong> ▶️ Incoming Webhook. The window will close, follow <strong>step 2</strong> 🔼 again.</li><li>Find and click 🖱 <strong>Configure</strong> ▶️ Incoming Webhook, give your webhook a name e.g. and upload a transparent picture of the service icon, ▶️ then click 🖱 <strong>Save</strong></li><li><strong>Copy</strong> the webhook <strong>URL</strong> and store it somewhere as we will need it for the next step.</li></ol><p>❗️You can always edit/delete/create multiple incoming webhooks for one or more teams/channels, and you can <strong>retrieve</strong> the URL of an existing webhook via the same steps, instead click 🖱 on <strong>Configured</strong> ◀️ menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*6KofuXS7lQmYLf2KPDZRoA.png" /><figcaption>Screenshot of Microsoft Teams <strong>team</strong>, <strong>channel</strong> and configuring the <strong>Incoming</strong> <strong>Webhook</strong></figcaption></figure><h4>3. Configuration of the AWS Lambda Function</h4><p>🔥 <strong><em>this</em></strong> section of the implementation is the biggest chunk!</p><p>We need to create the Lambda Function before the API because the API will need that resource created first. I will be doing this manual via the AWS console, you may choose a better method like IaC ▶️ Terraform, you can find the module <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function">here</a>.</p><ol><li>Open and Sign into the AWS Console, pick the region you would like to deploy the lambda in. ❗️this <strong><em>should</em></strong> ideally be in the same region the API Gateway will be in, however, if you need to deploy it in a different region be mindful that response time between invocations may be longer and more costly.</li><li>Navigate to the Lambda service (or search).</li><li>Click 🖱 the “Create function” button.</li><li>Choose “Author from scratch”.</li><li>Enter a <strong>name</strong> for your function, select your preferred <strong>runtime</strong> as Python 3.9, and choose “Create function” ▶️ leave the rest of the settings as is.</li><li>You will now see the Lambda function editor. You can write the code directly in this editor, or you can upload a ZIP file containing the code.</li></ol><blockquote><strong>Lambda Function (code)</strong></blockquote><p>I have written the lambda function ▶️ <a href="https://github.com/TechyTish/custom-microsoft-teams-incoming-webhooks/tree/pingdom-to-microsoft-teams"><strong>here</strong></a>. In this repository you will find 4 files, these are what is required to run the lambda function.</p><ul><li><a href="https://github.com/TechyTish/custom-microsoft-teams-incoming-webhooks/blob/pingdom-to-microsoft-teams/domains.py">domains.py</a>: this is a list of domains that we want to use in our hostnames, this is optional</li><li><a href="https://github.com/TechyTish/custom-microsoft-teams-incoming-webhooks/blob/pingdom-to-microsoft-teams/regions.py">regions.py</a>: this is a list of AWS and azure regions to use in our hostnames, this is optional</li><li><a href="https://github.com/TechyTish/custom-microsoft-teams-incoming-webhooks/blob/pingdom-to-microsoft-teams/pingdom_hostnames.py">pingdom_hostnames.py</a>: this is a list of hostnames that we want to check, these should be setup in Pingdom as checks, this is optional</li><li><a href="https://github.com/TechyTish/custom-microsoft-teams-incoming-webhooks/blob/pingdom-to-microsoft-teams/lambda_function.py">lambda_function.py</a>: this is the main part that will look at the HTTP POST request from the API Gateway and send the message to a Microsoft Teams channel.</li></ul><p>Within the lambda editor, you can create each file and copy, paste and edit the code there, this will be easier to make quick changes and for testing.</p><p>🔥 Please read through the full codebase 👆 to try and get an understanding of what is going on, I have added comments to the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XrSUic-M9ypCDT6ut3QCDA.png" /><figcaption>Screenshot of the AWS<strong> Lambda Function</strong></figcaption></figure><blockquote><strong>Pingdom Payload (JSON)</strong></blockquote><p>The following is an example of the payload that is sent via HTTP POST to an endpoint receiving the alert.</p><ul><li>as you can see there are multiple <strong>objects</strong>, depending on your needs, we don’t need to see all the fields in the Microsoft Teams notification.</li><li>we also have to actually tell Microsoft what objects we want to see in the notification from the payload.</li><li>you can view more payload types from Pingdom ▶️ <a href="https://www.pingdom.com/resources/webhooks/#HTTP-check--POST-"><strong>here</strong></a></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e81f82dfad21aafa55f98da987bc11da/href">https://medium.com/media/e81f82dfad21aafa55f98da987bc11da/href</a></iframe><p>❗️in Pingdom, the hostname is whatever url you place in the box next to http property.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lbFrus-KIAx-mQb1tfq8tA.png" /><figcaption>Screenshot of the hostname field on the check in Pingdom</figcaption></figure><blockquote><strong>within the </strong><a href="https://github.com/TechyTish/custom-microsoft-teams-incoming-webhooks/blob/pingdom-to-microsoft-teams/lambda_function.py"><strong><em>lambda_function.py</em></strong></a><strong> <em>:</em></strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bc985254d9606e942ff84b0873d6d0c/href">https://medium.com/media/4bc985254d9606e942ff84b0873d6d0c/href</a></iframe><ul><li>in the next step when we deploy the REST API, we will add a mapping template that says we want X objects from the Pingdom payload.</li><li>then the lambda function will pick up those objects because we’ve defined them ⏫</li></ul><blockquote><strong>Environment Variables</strong></blockquote><ul><li>you may have seen in the code, there are some environment variables, these need to be set in the Lambda Function’s configuration settings.</li></ul><ol><li>Open the AWS Management Console and navigate to the AWS Lambda service.</li><li>Select the Lambda function for which you want to set environment variables.</li><li>Scroll down to the “Configuration” section and click on the “Environment variables” tab.</li><li>Click 🖱 on the “Edit” button to edit the environment variables.</li><li>Add the key-value pairs for the environment variables that you want to set.</li><li>Click on the “Save” button to save the environment variables.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da2361c8170beb5db50b17463f067124/href">https://medium.com/media/da2361c8170beb5db50b17463f067124/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k-Fm-RZ3tqrovMz1stJuLQ.png" /><figcaption>Screenshot shows environment variables added to our lambda function</figcaption></figure><blockquote><strong><em>❗️</em>Gotcha’s:</strong></blockquote><ul><li>whenever making changes to any of the python files, you will need to <strong>save</strong> the lambda ◀️ before <strong>deploying</strong> for changes to take affect.</li><li>if you change the main lambda <strong>filename</strong> you will have to update the Runtime settings for the handler 🔥. For example, I’ve named the main file <a href="https://github.com/TechyTish/custom-microsoft-teams-incoming-webhooks/blob/pingdom-to-microsoft-teams/lambda_function.py">lambda_function.py</a> so the handler is called <a href="https://github.com/TechyTish/custom-microsoft-teams-incoming-webhooks/blob/pingdom-to-microsoft-teams/lambda_function.py">l</a>ambda_function.lambda_handler</li></ul><blockquote><strong>Are you feeling lost? <em>😀, lets re-cap </em>at this stage…</strong></blockquote><ul><li>✅ your <strong>lambda</strong> should have the relevant python files</li><li>✅ you have your <strong>environment</strong> <strong>variables</strong> for the Microsoft Teams webhook added to the configuration</li><li>✅ you also have created an environment variable for the API token for authorisation</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PBl5fW__zlQgPeilSOK_Vg.png" /><figcaption>Screenshot of the file structure in AWS Lambda, the name is <strong>pingdom-to-msteams</strong></figcaption></figure><blockquote><strong>Testing the lambda</strong></blockquote><ul><li>before moving on, I strongly <strong>advise</strong> you test the lambda function actually works directly ➡️ with <strong>Microsoft Teams</strong></li><li>you can use the following json to test the notification</li></ul><ol><li>Open the AWS Lambda console.</li><li>Select your function from the list of functions.</li><li>Click 🖱 on the “Test” button in the top right corner of the screen.</li><li>In the “Configure test event” dialog, choose “Create new test event”.</li><li>Give your test event a name, for example “PingdomMessageCardTest”.</li><li><strong>Paste</strong> the JSON 👇 for the message card in the “Event body” section.</li><li><strong>Click</strong> 🖱 on the “Create” button to create the test event.</li><li><strong>Click</strong> 🖱 on the “Test” button again to run the test using the new event.</li><li><strong>Check</strong> the output of the test to ensure that the message card was sent successfully.</li></ol><p>❗️Note that in order to use the <strong>JSON</strong> correctly, the message card details in your lambda function, will need to match whatever is in the test. See examples 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4a200d706532ab6a6b23b28d17111e2/href">https://medium.com/media/f4a200d706532ab6a6b23b28d17111e2/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1GWh-ZaDmLNP05zZSUsu1w.png" /><figcaption>Screenshot of the notification in Microsoft Teams via <strong>Lambda Test</strong></figcaption></figure><blockquote><strong>Testing the message card .json via Postman</strong></blockquote><p>To simplify/isolate your tests and/or to help with debugging issues, you can use Postman to run tests locally.</p><ol><li><strong>Open</strong> Postman and create a new request.</li><li>Set the request method to POST.</li><li>Set the request URL to the webhook URL for your Microsoft Teams channel.</li><li><strong>Click</strong> 🖱 on the “Headers” tab and add a new header with the key “Content-Type” and the value “application/json”.</li><li><strong>Click</strong> 🖱 on the “Body” tab and select the “raw” radio button.</li><li>In the text area below, copy and paste the message card JSON from 🔼</li><li><strong>Click</strong> 🖱 the “Send” button to send the request.</li></ol><p>Once the request is sent 📫, the message card should appear in the Microsoft Teams channel specified in the webhook URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sptHyCzFy7d635V1T1sUag.png" /><figcaption>Postman test to <strong>Microsoft</strong> <strong>Teams, </strong>reports<strong> 200 OK</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LS0651ZBWB8b0ByWioEwzg.png" /><figcaption>Screenshot of the notification in Microsoft Teams via <strong>Postman</strong></figcaption></figure><blockquote><strong>Viewing how a .json payload is received via RequestBin</strong></blockquote><p>Using <a href="https://requestbin.com/">RequestBin</a> is such a powerful tool not just for looking at Pingdom payloads, but also <strong><em>any</em></strong> payload — here is how you can setup RequestBin and send a HTTP POST request to view the payload:</p><ol><li>Create a private RequestBin endpoint by going to <a href="https://requestbin.com/"><strong>https://requestbin.com</strong></a> and clicking 🖱 the “Create a RequestBin” button. Choose a name for your bin and click the “Create RequestBin” button.</li><li>Copy the URL of your private RequestBin endpoint. It should look something like “<a href="https://your-name-here-1234567890abcd1234567890abcd123.pipedream.net/">https://your-name-here-1234567890abcd1234567890abcd123.pipedream.net</a>&quot;.</li><li>In your Pingdom account, create a new Integration by clicking on settings ▶️ integrations ▶️ add integration</li><li>Enter the name i.e. RequestBin Endpoint</li><li>Enter the URL of your private RequestBin endpoint in the “URL” field.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*niMyTaaJJhHfQ0QCa6wxmw.png" /><figcaption>Creating an integration webhook in Pingdom for <strong>RequestBin</strong></figcaption></figure><ol><li>Go to any of your checks (or the Google one) in Pingdom, you should now see the new integration in the list.</li><li>Tick the box and ▶️ Modify Check</li><li>Once the page has reloaded, go back into the check and click 🖱 “Test”</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aymhyLmtPCeO2omitJfApA.png" /><figcaption>Modifying the existing check &amp; Test</figcaption></figure><ul><li>❗️if your RequestBin endpoint requires authentication, enter the necessary credentials in the “Authentication” section.</li><li>optionally, you can add request headers, request body parameters, and other advanced settings in the appropriate sections.</li><li>Pingdom will now send a POST request to your private RequestBin endpoint at the specified URL. You can view the details of each request by going to your RequestBin dashboard and selecting the appropriate bin.</li></ul><p>❗️<strong><em>Note</em></strong>: If you’re using a private RequestBin endpoint, you don’t need to worry about authorisation since only you have access to the endpoint. However, if you’re using a public endpoint or an endpoint that requires authentication, you may need to provide credentials or API keys to Pingdom to ensure that the check is authorised to access the endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UgJB38XHnv49h2nKe_wIpA.png" /><figcaption>Pingdom payload viewed in RequestBin, in <strong>Pretty</strong> view</figcaption></figure><h4>4. Configuration of the AWS API Gateway</h4><ol><li>Once you have written and tested your lambda function, navigate to the API Gateway service.</li><li><strong>Click</strong> 🖱 “Create API” and select “REST API”.</li><li>Choose ▶️ “Build” in the “REST API” column.</li><li>Choose ▶️ “New API” and enter a name for your API.</li><li>Choose ▶️ “Create API”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jMFPhnqly8zCMY1tNQ_Kmw.png" /><figcaption>Screenshot of creating<strong> REST API</strong> in AWS</figcaption></figure><blockquote><strong>Modifying the POST method &amp; mapping template</strong></blockquote><p>So in order for our lambda function to receive the payload and then send it to Microsoft Teams, it needs to be “formatted” in the correct way.</p><p>Once your API is created, <strong>click</strong> 🖱 on the “Actions” button and select “Create Method”.</p><ol><li>Select the HTTP method (e.g. POST) that your API will use.</li><li>Choose “Lambda Function” as the integration type, and select the region where your Lambda function is deployed.</li><li>Enter the name of your Lambda function and click “Save”.</li><li>Your API is now created and integrated with your Lambda function. You can test your API by clicking the “Test” button in the API Gateway console.</li></ol><blockquote><strong>Configuring POST method resource on API</strong></blockquote><blockquote><strong>Method Request</strong></blockquote><ul><li>▶️ leave as <strong>default</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ei7sq8emE0vtlvIWh2yy_w.png" /><figcaption>Screenshot of the <strong>POST — Method Request</strong></figcaption></figure><blockquote><strong>Integration Request</strong></blockquote><p>this is how the payload will be received</p><ul><li><strong>type: </strong>Lambda</li><li><strong>region:</strong> select the region your lambda was deployed to</li><li><strong>lambda function: </strong>select your lambda function</li><li><strong>mapping templates:</strong></li><li><strong>▶️ request body passthrough:</strong> When there are no templates defined (recommended)</li><li>▶️ <strong>Content-Type:</strong> application/json</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eeUGNa_Cae9bWJUQ5eLyqA.png" /><figcaption>Screenshot of the <strong>POST — Integration Request</strong></figcaption></figure><ul><li><strong>Template</strong> ▶️ should include how it is configured in the lambda</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfc9170cb42652e8138d2d6df12ae3af/href">https://medium.com/media/cfc9170cb42652e8138d2d6df12ae3af/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IoZRBEMSSSenQTFoBNu6FQ.png" /><figcaption>Screenshot of the <strong>mapping template</strong> for the REST API</figcaption></figure><blockquote><strong>Method Response</strong></blockquote><ul><li>▶️ <strong>Content-type: </strong>application/json</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GXOEUUSOceP9ugp2lsot2Q.png" /><figcaption>Screenshot of the <strong>POST — Method Response</strong></figcaption></figure><blockquote><strong>Integration Response</strong></blockquote><p>this is the response you will see in the console, e.g. Postman on the response when you send a POST request</p><ul><li><strong>method response: </strong>200</li><li><strong>mapping templates:</strong> Content-Type: application/json &amp; include the following:</li></ul><pre>#set($inputRoot = $input.path(&#39;$&#39;))<br>#set($message = &quot;Notification sent successfully&quot;)<br>{<br>    &quot;message&quot;: &quot;$message&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BdLV4tBa62BfhNCG0RrBpg.png" /><figcaption>Screenshot of the <strong>POST — Integration Response</strong></figcaption></figure><p>❗️<strong>Gotcha’s:</strong> if you <strong>define</strong> a object to retrieve in the Lambda Function, but don’t define it in the <strong><em>mapping template</em></strong> in the REST API, you may see an error in the AWS Cloudwatch Logs for the lambda like</p><pre>Response<br>{<br>  &quot;errorMessage&quot;: &quot;&#39;hostname&#39;&quot;,<br>  &quot;errorType&quot;: &quot;KeyError&quot;,<br>  &quot;requestId&quot;: &quot;e162163a-8f6e-4ea9-962c-7343ff0eb540&quot;,<br>  &quot;stackTrace&quot;: [<br>    &quot;  File \&quot;/var/task/lambda_function.py\&quot;, line 14, in lambda_handler\n    hostname = data[&#39;hostname&#39;]\n&quot;<br>  ]<br>}</pre><blockquote><strong>Deploy the API</strong></blockquote><p>whenever you make changes to the API you must deploy it to a stage</p><ul><li><strong>deploy</strong> your API to a stage by clicking 🖱 on the “Actions” dropdown and selecting “Deploy API”.</li><li><strong>choose</strong> a deployment stage and click “Deploy”.</li><li>you will now be able to retrieve your REST API endpoint url</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZtlrnrOWYA2VBaglqIZN2w.png" /><figcaption>Screenshot of the Stage “<strong>development</strong>” being deployed</figcaption></figure><h4>5. Logging &amp; Testing</h4><blockquote><strong>Enable logging</strong></blockquote><p>Logging is important to us because we will be able to <strong>trace</strong> issues whilst <strong>debugging</strong> errors by looking at the logs. By default, logging is enabled on the Lambda Function, but we <strong>need</strong> to enable it on the API, follow these steps:</p><ol><li>From the ◀️ left-hand menu in the API, choose “Stages”.</li><li>Choose the name of the API’s stage that you want to enable logging for.</li><li>From the “Logs/Tracing” tab, turn on “Enable CloudWatch Logs”.</li><li>Optionally, you can specify a log level and a CloudWatch Logs role ARN if you want to customise the logging behaviour.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LdNoJmjsZb-8f06E0_FH5g.png" /><figcaption>Screenshot of API <strong>logging</strong> enabled</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PgTtKI0Jjeib6BmMyDWLpg.png" /><figcaption>Screenshot of the <strong>Lambda Function</strong> logs menu</figcaption></figure><p>Once you enable logging, API Gateway automatically creates a CloudWatch Logs log group and log stream for the selected stage of your API. You can then view your API’s logs in the CloudWatch console or use CloudWatch Logs APIs to programmatically retrieve and analyse your logs.</p><blockquote><strong>Testing</strong></blockquote><p>Before we can invoke the REST API endpoint, we need to actually add it to Pingdom.</p><blockquote><strong>Add API endpoint url to Pingdom</strong></blockquote><ol><li>Log in to your Pingdom account and navigate to the Integrations page.</li><li><strong>Click</strong> 🖱 on the “Add integration” button.</li><li>Select the type of integration you want to create (e.g., webhook).</li><li>Enter a name for the integration and enter the the REST API url for the webhook.</li><li><strong>Save</strong> the integration.</li><li>To send a test message to the API on Pingdom, click on the “Send test” button next to the integration you just created.</li><li>Verify that the test message was received by the API and processed as expected. ◀️ Can be seen in the <strong>CloudWatch</strong> logs</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*THA3iUIVa57CvnjXqkLsOg.png" /><figcaption>Screenshot of adding the API url to the check</figcaption></figure><p>To update an existing integration on Pingdom, follow these steps:</p><ol><li>Log in to your Pingdom account and navigate to the Integrations page.</li><li><strong>Click</strong> 🖱 on the integration you want to update.</li><li>Make the necessary changes to the integration settings.</li><li><strong>Save</strong> the changes.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*raxzys8xu-DM2uNyBVha6Q.png" /><figcaption>Screenshot of the Microsoft Teams notification triggered from Pingdom to API endpoint for <strong>check_google </strong>&amp; delivered via AWS Lambda Function</figcaption></figure><h3>Security</h3><p>You’ve probably wondered why the hell is everything open? Well, for the most basic setup its still secure to an extent, my <strong>top tips</strong> 💡 to make this solution secure for production workloads:</p><p>🔐 Deploy resources using <strong>Infrastructure as Code</strong> such as, Terraform</p><p>🔐 Create an AWS <strong>Virtual Private Cloud</strong> which will enable the API to sit behind protocols and ensure the connection is private</p><p>🔐 <strong>Secure your AWS Lambda function:</strong> Ensure that your AWS Lambda function is secure by using the latest version of your programming language and framework, keeping your dependencies up to date, and implementing security best practices.</p><p>🔐 Create an <strong>API access token</strong>, use this token on header requests in the lambda function and in the Pingdom check</p><p>🔐 <strong>Use secure authentication:</strong> Use secure authentication mechanisms to authenticate requests to your AWS API Gateway and AWS Lambda functions. You can use AWS Cognito or OAuth 2.0 to authenticate users and services.</p><p>🔐 <strong>Implement access control: </strong>Configure access control policies on your AWS API Gateway to ensure that only authorized users and services can access the API. You can use AWS IAM policies to control access to your resources.</p><p>🔐<strong> Implement SSL/TLS encryption:</strong> Ensure that all communication between Pingdom, AWS API Gateway, AWS Lambda, and Microsoft Teams is encrypted using SSL/TLS. This will help to protect your data in transit from unauthorized access.</p><p>🔐 <strong>Implement rate limiting: </strong>Implement rate limiting on your AWS API Gateway to prevent API abuse and protect against denial of service attacks.</p><p>🔐 <strong>Monitor and log activity:</strong> Implement logging and monitoring to detect and respond to security incidents. You can use AWS CloudTrail, Amazon CloudWatch Logs, and Amazon CloudWatch Metrics to monitor and log activity.</p><p>🔐 <strong>Keep up to date with security patches:</strong> Ensure that all software and systems are kept up to date with the latest security patches and updates to minimise the risk of known vulnerabilities being exploited.</p><p>By following these measures, you can significantly increase the security of your infrastructure.</p><h3>Troubleshooting</h3><p>Obviously you will more than likely run into some issues, I did, we all do.</p><blockquote>❗️Look at the <strong>AWS</strong> <strong>CloudWatch Logs</strong>, it will tell you what the error is</blockquote><blockquote>❗️Remember to use <strong>Postman</strong></blockquote><blockquote>❗️Remember to use <strong>RequestBin</strong></blockquote><p>If you’re <strong><em>really</em></strong> stuck, you may reach out to me &amp; connect via <a href="https://www.linkedin.com/in/letitia-hutchinson/"><strong>LinkedIn</strong></a></p><h3>Conclusion</h3><p>So we have configured sending Pingdom checks to Microsoft teams using REST API and AWS Lambda.</p><ul><li>💡 All in all, when a check is triggered in Pingdom, the payload is sent to the API endpoint, the lambda is then invoked which accepts the payload, takes the relevant objects we specified and sends it to Microsoft Teams in a nice pretty format.</li></ul><p>Let’s have a quick check of what we’ve done!</p><blockquote><strong>Part 1</strong></blockquote><ul><li>✅ discussed what the issue is with Pingdom sending notifications to Microsoft Teams</li><li>✅ discussed what the solution would involve, leveraging AWS API and Lambda</li><li>✅ discussed the costing estimates of invoking the API and Lambda 50 times a day for a month</li><li>✅ discussed the tools and technologies you require access to implement the solution</li></ul><blockquote><strong>Part 2</strong></blockquote><ul><li>✅ created an incoming webhook url on Microsoft Teams</li><li>✅ created an AWS Lambda function using Python</li><li>✅ tested the AWS lambda function sends to Microsoft Teams</li><li>✅ configured how to use Postman to test locally</li><li>✅ configured how to use RequestBin to view payloads</li><li>✅ created an AWS REST API to receive the payload</li><li>✅ configured POST method on the API, utilising the message template</li><li>✅ created a stage (environment) and deployed it, which gives us our API endpoint url</li><li>✅ went over <strong>security</strong> improvements you may want to make</li><li>✅ created an integration webhook in Pingdom and modified our check to send a test</li><li>✅ sent the <strong><em>final</em></strong> check and it displayed in Microsoft Teams</li></ul><h4>🎉 I would like to <strong>congratulate</strong> you on making it to the end of this project!!! 😂</h4><h3>Source Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*doD70Zf_pzR4g2-paEkLQw.png" /><figcaption>GitHub profile page</figcaption></figure><p>➡️ Visit my <a href="https://github.com/TechyTish/aws-real-world-projects/tree/pingdom-to-microsoft-teams"><strong>GitHub</strong></a> repository for the source code for this service and fork the repo. Happy coding! 💻</p><p>😃 I will be adding more services overtime and you will be able to access them via the branch name.</p><h3>💭 Thank you for reading!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25119873825f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Pingdom & Microsoft Teams (Part 1/2)]]></title>
            <link>https://medium.com/@techytish/integrate-pingdom-microsoft-teams-part-1-2-d0ef36e3f81c?source=rss-9da100b017f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0ef36e3f81c</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pingdom]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[microsoft-teams]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Tish H.]]></dc:creator>
            <pubDate>Sun, 05 Mar 2023 22:14:03 GMT</pubDate>
            <atom:updated>2023-03-19T15:42:32.674Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi and welcome 👋, are you migrating to Microsoft Teams or maybe you have recently configured Pingdom to monitor web pages?</p><p>As a <strong><em>DevOps + Cloud Infrastructure Engineer &amp; Developer</em></strong>, I use a lot of different monitoring tools to provide metrics/alerts of many different products/services.</p><p>It’s important that if something has been configured for monitoring that you and your team are aware of any critical alerts that affect your production environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*tZPxV72auzOUQ60BCVV9CA.png" /><figcaption>Tools &amp; Technologies used for Implementation</figcaption></figure><h3>Part 1/2 Summary</h3><ul><li><strong>current problem</strong>, defining the issue between Pingdom and Microsoft Teams</li><li><strong>solution overview</strong>, defining how the issue is being solved</li><li><strong>pre-requisite technologies</strong>, listing the tools &amp; services you need to have access to</li><li><strong>costing</strong>, how much will the aws lambda &amp; aws api gateway cost?</li></ul><h3>1. So what’s the problem….</h3><p><a href="https://www.pingdom.com/why-pingdom/">Pingdom</a> is a tool I use at work to monitor uptime of several different web applications. It allows us to be alerted based on different types of requests. For example, we need to know if the application gateway that sits behind our web server is up/down, Pingdom can send timed interval HTTP checks to see if the application gateway is reachable.</p><ul><li>The service provided notifications to Slack using the Pingdom Slack app, we’re migrating to Microsoft Teams and so any monitoring tools in place need to be updated to alert us in Microsoft Teams.</li><li>There is a Microsoft Teams Pingdom app that can be installed on a Team or Channel but it’s broken, the integration does not work.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/0*0JYmuvT4x5JU_NsG.png" /><figcaption>Pingdom Microsoft Teams Application, source is <a href="https://appsource.microsoft.com/en/product/office/wa104381605?tab=overview&amp;exp=ubp8">Microsoft</a></figcaption></figure><blockquote><strong>WHY</strong>: When the HTTP request is sent from Pingdom (when an check is triggered) to Microsoft Teams it’s in the form of a payload, this is in JSON format. The payload Pingdom sends is not compatible with how Microsoft Teams needs it.</blockquote><p><strong>So we now have 2 options:</strong><br>1. ❌ replace Pingdom with another service: this is more time consuming &amp; may cost more<br>2. ✅ find the root of the problem and fix it myself: <strong>ding ding ding! 🔔</strong></p><h3>2. Solution Overview</h3><p>Using <a href="https://aws.amazon.com/api-gateway/">AWS API Gateway</a> and <a href="https://aws.amazon.com/lambda/">AWS Lambda</a>, when the check is triggered in Pingdom, it will send the notification to the AWS API endpoint (url).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sWjJt2TxkQkW2lt5.png" /><figcaption>Amazon API Gateway &amp; Lambda function images</figcaption></figure><ul><li>When a message is sent via HTTP, it&#39;s identified as a payload. This is received in JSON format.</li><li>So the API receives the payload, we specify which data from the payload we’re interested in using a mapping template on the POST request.</li><li>The AWS Lambda Function will receive an invoke response from the API Gateway, this is setup as a trigger</li><li>The AWS Lambda Function is written in Python, the script defines how to send the payload to a Microsoft Teams channel using an incoming webhook url (in a way that Microsoft accepts), this is known as a message card.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*etbdLQ5UtEmmnWpc.png" /><figcaption>Example of a message card in Microsoft Teams. Source is <a href="https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/design-effective-cards?tabs=design">Microsoft Documentation</a></figcaption></figure><h3>3. Pre-Requisite Technologies</h3><p>In order to follow along with implementation, you will need to have access to the the following services (preferably as an admin/owner):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QZKAcxLaV_5PaiIz.png" /><figcaption>Amazon Web Services, Pingdom, Microsoft Teams, Python, REST API, Postman &amp; RequestBin</figcaption></figure><ul><li><a href="https://aws.amazon.com/"><strong>AWS</strong></a> account</li></ul><blockquote>permissions to create resources in AWS</blockquote><blockquote>permissions to access AWS CloudWatch Logs</blockquote><ul><li><a href="https://www.pingdom.com/"><strong>Pingdom</strong></a> account</li></ul><blockquote>with checks configured</blockquote><blockquote>and permissions to add integration webhook urls</blockquote><ul><li><a href="https://www.microsoft.com/en-us/microsoft-teams/log-in"><strong>Microsoft</strong> <strong>Teams</strong></a> account</li></ul><blockquote>with permissions to add Incoming Webhook connector</blockquote><blockquote>and create teams/channels</blockquote><ul><li><a href="https://www.python.org/about/gettingstarted/"><strong>Python</strong></a> knowledge:</li></ul><blockquote>you <strong>don’t</strong> need advanced knowledge, but a basic understanding</blockquote><blockquote>the AWS Lambda Function is written in Python v3.9</blockquote><ul><li><a href="https://medium.com/extend/what-is-rest-a-simple-explanation-for-beginners-part-1-introduction-b4a072f8740f"><strong>RESTful API</strong></a><strong> </strong>knowledge:</li></ul><blockquote>as the API we’re creating is an REST Api</blockquote><blockquote>and the Lambda will be using this to communicate (send/receive HTTP requests) with Microsoft Teams</blockquote><ul><li><a href="https://www.postman.com/"><strong>Postman</strong></a> account:</li></ul><blockquote>this is optional</blockquote><blockquote>we will use this test HTTP requests locally</blockquote><ul><li><a href="https://requestbin.com/"><strong>Request Bin</strong></a> account:</li></ul><blockquote>this is optional</blockquote><blockquote>we will use this to see see how a payload request is formatted</blockquote><h3>4. Costing</h3><p>Assuming that the Lambda function runs for a maximum of 50 invocations per day, and each invocation completes within 1 second, the total monthly cost for AWS API Gateway and Lambda (EU Ireland region), can be estimated as follows:</p><blockquote><strong>API Gateway</strong></blockquote><ul><li>Requests: 50 requests/day x 30 days = 1,500 requests/month</li><li>Data transfer out: Assuming an average payload size of 1KB per request, the total data transfer out per month would be 1.5 MB.</li><li>Cost = 1,500 requests * £0.0000004/request + 1.5 MB * £0.09/GB = £0.0006 + £0.0001 = £0.0007</li></ul><blockquote><strong>Lambda</strong></blockquote><ul><li>Execution: Assuming an average execution time of 200ms per request, the total compute time per month would be 50 requests * 200ms/request = 10 seconds.</li><li>Memory: Assuming you use 128MB of memory for your Lambda function.</li><li>Cost = 10 seconds * 128MB * £0.000000208/GB/second = £0.0000026</li></ul><p>Therefore, the estimated monthly cost for the API Gateway and Lambda usage would be approximately £0.0007 + £0.0000026 = £0.0007026.</p><p>Also remember the 50 invocations is when a Pingdom check is activated, so this will be if the state changes, or if a test alert is sent.</p><p>🔥 Please note that these are estimates and actual costs may vary depending on factors such as region the resources are provisioned in, traffic spikes and data transfer.</p><blockquote><strong>AWS Calculator</strong></blockquote><p>You can estimate your AWS costs using the AWS Simple Monthly Calculator, which allows you to estimate the monthly costs of running your services based on your usage. You can access it here: <a href="https://calculator.aws/#/">https://calculator.aws/#/</a></p><blockquote><strong>AWS Pricing</strong></blockquote><p>You can also view the AWS pricing page for a detailed breakdown of pricing for all AWS services. Here’s the link: <a href="https://aws.amazon.com/pricing/">https://aws.amazon.com/pricing/</a></p><blockquote><strong>Other Tools</strong></blockquote><ul><li>Request Bin and Postman is free</li><li>I assume you already have an Pingdom and Microsoft Teams account, which likely incurs other costs not accounted for above.</li></ul><h3>Part 2/2 Summary</h3><ul><li><strong>implementation</strong>, build and deploy the solution</li><li><strong>testing</strong> the solution works</li><li><strong>along</strong> with some gotcha’s, troubleshooting guidance</li><li><strong>security</strong> improvements you may want to make</li><li>✅ you can read the article ▶️ <a href="https://medium.com/@techytish/integrate-pingdom-microsoft-teams-part-2-2-25119873825f"><strong>here</strong></a></li></ul><h3>Source Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*doD70Zf_pzR4g2-paEkLQw.png" /><figcaption>GitHub profile page</figcaption></figure><p>➡️ Visit my <a href="https://github.com/TechyTish/aws-real-world-projects/tree/pingdom-to-microsoft-teams"><strong>GitHub</strong></a> repository for the source code for this service and fork the repo. Happy coding! 💻</p><p>😃 I will be adding more services overtime and you will be able to access them via the branch name.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0ef36e3f81c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[100 Days of Code: Day 4 & Day 5]]></title>
            <link>https://medium.com/@techytish/100-days-of-code-day-4-day-5-493be1a684e6?source=rss-9da100b017f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/493be1a684e6</guid>
            <category><![CDATA[100daysofcode]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Tish H.]]></dc:creator>
            <pubDate>Sun, 12 Jun 2022 14:36:28 GMT</pubDate>
            <atom:updated>2022-06-12T14:44:38.901Z</atom:updated>
            <content:encoded><![CDATA[<p>On Day4 &amp; Day 5 of the #100daysofcode challenge, we pick up from where we left off on <a href="https://medium.com/@techytish/100-days-of-code-day-3-25cd35db6be2">Day3</a>. We learn more about if statements, logical operators, and theres not 1, 2 but 3 exercises that we will complete before taking on the project which is an Adventure Story game where you choose your fate!</p><p>We also start to use &amp; create flowcharts to help us visualise in diagram format how a conditional statement should behave which is fun!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*55la0vAvhBiOi73f" /><figcaption>Photo by <a href="https://unsplash.com/@synkevych?utm_source=medium&amp;utm_medium=referral">Roman Synkevych 🇺🇦</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you haven’t already checked out my previous day, please go and give it a read <a href="https://medium.com/@techytish/100-days-of-code-day-3-25cd35db6be2">here</a>.</p><blockquote>*100daysofcode Link: <a href="https://tidd.ly/3GNwiIt">https://tidd.ly/3GNwiI</a></blockquote><h3>Exercises &amp; Concepts Learnt</h3><p>So as explained we’re picking up with where I left off with 3 remainder exercises to allow us to test our knowledge on the concepts we’ve learnt.</p><p>Before we get into the code of 1 of the exercises, we’re introduced to <a href="https://app.diagrams.net/">draw.io</a> an awesome tool that allows us to draw diagrams such as flowcharts which are useful if you want to visually see how something is designed from a high level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uDmmoeaP1m0a-gXZ" /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=medium&amp;utm_medium=referral">Kelly Sikkema</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><pre>Write a program that works out whether if a given year is a leap year. </pre><p>To calculate a leap year we need to consider the following:<br>— — — — — — — — “ — — — — — — — <br><strong><em>**on** </em></strong><em>every</em><strong><em> </em></strong><em>year that is evenly divisible by 4 <br></em><strong><em>**except**</em></strong><em> every year that is evenly divisible by 100 <br></em><strong><em>**unless** </em></strong><em>the year is also evenly divisible by 400<br></em> — — — — — — — — “ — — — — — — —</p><blockquote><strong>💡Tip! </strong>Now let’s put this statement into a flowchart to help visualise understand how we want it to work before writing the conditional statement in code.<strong> </strong><em>I am using the</em><strong><em> draw.io extension </em></strong><em>in VSCode.</em> Remember <strong>all</strong> 3 of the above statements have to be met in order for the number to be a leap year.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*5sBddytVnR6A7PL6taG4Iw.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f8e2616d105f7c795b8f50566013bbe/href">https://medium.com/media/5f8e2616d105f7c795b8f50566013bbe/href</a></iframe><pre>More <strong>ifs, elifs, else </strong>statements &amp; <strong>logical</strong> operators</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5046a6153cda2957e77cf29eb2e739a0/href">https://medium.com/media/5046a6153cda2957e77cf29eb2e739a0/href</a></iframe><pre>Pizza order programme</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/615d293f196b47e1826d1fa68ceee156/href">https://medium.com/media/615d293f196b47e1826d1fa68ceee156/href</a></iframe><pre>Write a program that tests the compatibility between <strong>two</strong> people.</pre><p>To work out the love score between two people:<br> — — — — — — — — “ — — — — — — — <br>**Take <strong>both</strong> people’s names** and check for the number of times the letters in the words <strong>TRUE</strong> and <strong>LOVE</strong> occurs. <br>**Then <strong>combine</strong>** these numbers to make a <strong>2 digit </strong>number.<em><br></em> — — — — — — — — “ — — — — — — —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c73e1cdb0a34185d4c57a10ece933ca0/href">https://medium.com/media/c73e1cdb0a34185d4c57a10ece933ca0/href</a></iframe><h3>Day 3 | Project “Choose Your Fate”</h3><p>So Day 3’s project is a choice based style game, so depending on the choices the user makes will decide their fate. I have decided to use an existing story from <a href="https://textadventures.co.uk/games/view/jbspv5gvseo2ihppwyot2g/the-silver-key"><strong>Text Adventures</strong></a> and turn it into code! The aim of this game is to find the silver key, it is behind 1 of 3 doors.</p><p>The project needs to contain the following:</p><ul><li>Use conditionals such as <strong>if</strong>, <strong>elif</strong>, and <strong>else</strong> statements.</li><li>Create a <strong>flow chart</strong> to demonstrate visually how the game is won.</li><li>Make user inputs less case sensitive i.e. “<strong>enter</strong>” can be inputted as “<strong>Enter</strong>”.</li><li><em>Optional</em>: Use ascii art to add an image for the game.</li></ul><pre>Flow chart for ‘<strong>The Silver Key</strong>’ game</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*DPsq6CeB5lIiSkxjHgdUQg.png" /></figure><pre>Let&#39;s have a look at how the game runs!<br><strong>Door 1</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*fQVHeLflDT0Oss-xb-46Ow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*pAdJ1yner7w7TMWKmQDx3A.png" /></figure><pre><strong>Door 2</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*zWLpjkv_QfIqoQTUfMJIaA.png" /></figure><pre><strong>Door 3</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*LVfm2gpt38tLq5rO6fYmOg.png" /></figure><p>Check out my <a href="https://github.com/TechyTish/100daysofcode">GitHub repository</a> for the exercises, flowcharts, concepts &amp; project solution from Day 3 (this is a continuation). This also shows you my failed attempts in my commit history.</p><blockquote>*Please note the link provided to the 100daysofcode bootcamp course is affiliated. I will receive a small % from each purchase.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=493be1a684e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[100 Days of Code: Day 3]]></title>
            <link>https://medium.com/@techytish/100-days-of-code-day-3-25cd35db6be2?source=rss-9da100b017f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/25cd35db6be2</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[100daysofcode]]></category>
            <dc:creator><![CDATA[Tish H.]]></dc:creator>
            <pubDate>Fri, 10 Jun 2022 23:16:13 GMT</pubDate>
            <atom:updated>2022-06-11T16:41:29.520Z</atom:updated>
            <content:encoded><![CDATA[<p>On Day3 of the #100daysofcode challenge we <strong>FINALLY</strong> 🤓 are going to be learning the fundamentals of conditional statements — if, elif, else this makes coding so much easier, cleaner and less repetitive code. We will also learn about logical operators, code blocks &amp; scope.</p><p>I am really <strong>enjoying</strong> this course, it’s the right amount of challenge from the get go, you learn the concepts, do exercises, partake in quizzes to test your knowledge and you then get to combine everything and build a tool which really is the ultimate test.</p><p>I am doing this course in the evening after a <strong><em>working</em></strong> full-time (I’m a Cloud Infrastructure Engineer) so my brain takes a minute to catchup lol 🤣🤣. So if you’re in the same boat don’t worry if it takes you longer to understand the concepts being taught.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KVca1ErP4-b9--NU" /><figcaption>Photo by <a href="https://unsplash.com/@milada_vigerova?utm_source=medium&amp;utm_medium=referral">Milada Vigerova</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you haven’t already checked out my previous day, please go and give it a read <a href="https://medium.com/@techytish/100-days-of-code-day-2-e7b818b5aef3">here</a>.</p><blockquote>*100daysofcode Link: <a href="https://tidd.ly/3GNwiIt">https://tidd.ly/3GNwiI</a></blockquote><h3>Exercises &amp; Concepts Learnt</h3><p>Below are a few of the concepts learnt in Day3 of the course and exercises to practice those concepts. This was a great way to get familiar with conditional statements and how to manipulate user inputs and output results based on the condition you have defined.</p><pre><strong>if/else</strong> conditions - we want to do <strong>a</strong> or <strong>b</strong></pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1951b5a892488dfa6dd68fcf87d35515/href">https://medium.com/media/1951b5a892488dfa6dd68fcf87d35515/href</a></iframe><pre>Write a program that works out whether if a <strong>given</strong> number is an <strong>odd</strong> or <strong>even</strong> number.</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a4be8eca15c41b86924f565cbfc70ad/href">https://medium.com/media/8a4be8eca15c41b86924f565cbfc70ad/href</a></iframe><pre><strong>nested if </strong>conditions - we want <strong>a</strong> and <strong>b</strong> to be true</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee3c34e01ed710e3214cd4ba4da2fb4f/href">https://medium.com/media/ee3c34e01ed710e3214cd4ba4da2fb4f/href</a></iframe><pre><strong>bmi calculator v2</strong> - determine user weight category based on input and use <strong>elif</strong> statement</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2b74de5306e91c54c07d57f68f0bb68/href">https://medium.com/media/c2b74de5306e91c54c07d57f68f0bb68/href</a></iframe><p>So today is a Friday, it is 12:10am, I’ve had a busy day at work, been out for a meal and I’m ready for my bed haha 🥱 😴. Having a quick peak at the upcoming days and the content appears to grow in terms of exercises and concepts to cover each day.</p><p>Going forwards I will be committing to 1–2 hours a day and picking up where I left off the next day. My aim is that, to continuously code for 1–2 hours in Python each day, not complete all 100 projects!</p><p>Please do check out my <a href="https://github.com/TechyTish/100daysofcode">GitHub repository</a> for the exercises, concepts I’ve completed so far from Day3. This also shows you my failed attempts in my commit history.</p><blockquote>*Please note the link provided to the 100daysofcode bootcamp course is affiliated. I will receive a small % from each purchase.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25cd35db6be2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[100 Days of Code: Day 2]]></title>
            <link>https://medium.com/@techytish/100-days-of-code-day-2-e7b818b5aef3?source=rss-9da100b017f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7b818b5aef3</guid>
            <category><![CDATA[100daysofcode]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Tish H.]]></dc:creator>
            <pubDate>Thu, 09 Jun 2022 22:04:22 GMT</pubDate>
            <atom:updated>2022-06-09T22:09:39.894Z</atom:updated>
            <content:encoded><![CDATA[<p>On Day2 of the #100daysofcode challenge we dive deeper in learning more about manipulating strings and we move onto data types (defining variables differently).</p><p>If you haven’t already checked out my previous day, please go and give it a read <a href="https://medium.com/@techytish/100-days-of-code-day-1-63f129f08daa">here</a>.</p><blockquote><em>*</em>100daysofcode Link: <a href="https://tidd.ly/3GNwiIt">https://tidd.ly/3GNwiIt</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*bqFt6gi9_c_TUiT7fRsBPQ.png" /></figure><h3>Exercises &amp; Concepts Learnt</h3><p>Below are a few of the concepts learnt in Day2 of the course and exercises to practice those concepts. This was definitely a step up from Day 1 in terms of concepts and things to pick up. With heavy focus on maths + data manipulation.</p><pre>learning datatypes</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9e5f06aacaeeff45d7ccc39b7ca7c3b/href">https://medium.com/media/d9e5f06aacaeeff45d7ccc39b7ca7c3b/href</a></iframe><pre>conversion functions using data types</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0af3063d88d47bc9e5afb088ca5c054a/href">https://medium.com/media/0af3063d88d47bc9e5afb088ca5c054a/href</a></iframe><pre>string to integer conversion &amp; using math operators to calculate an sum</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e420ec9a76c187b9f3ea94fd54a1d11/href">https://medium.com/media/6e420ec9a76c187b9f3ea94fd54a1d11/href</a></iframe><pre>writing a program that calculates BMI from user input</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99fb5cdb643311418579db1c02288729/href">https://medium.com/media/99fb5cdb643311418579db1c02288729/href</a></iframe><pre>Create a program using maths and f-Strings that tells us how many days, weeks, months we have left if we live until 90 years old.</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/483785627889798085267dc860e8b06a/href">https://medium.com/media/483785627889798085267dc860e8b06a/href</a></iframe><blockquote><strong><em>💡Tip! </em></strong>When tackling exercises, break it down like a story, find where you think variables need to be created in order for values to be stored and think about where manipulation needs to occur.</blockquote><h3>Day 2 | Project “Tip Calculator”</h3><p>So todays project is a tip calculator. The programme will ask for the following:</p><ul><li>how much was the total bill?</li><li>how much percentage of tip to pay (10, 12 or 15%)</li><li>how many people is the bill being split between?</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*owq7h1Zz60AeZ_4Oj7qywA.png" /></figure><p>Then it will calculate the final bill per a person (rounded to 2 decimal places). You can see below my working solution via running the script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*-S9jGtP_J_W_W2_7-niunA.png" /></figure><blockquote><strong><em>💡Tip! </em></strong>My calculations are not as good as they used to be <em>😂</em>, I’d highly recommend writing out maths like this on a piece of paper to help determine where you need to do your calculations in code. It’s a bit like pseudocode.</blockquote><p>Check out my <a href="https://github.com/TechyTish/100daysofcode">GitHub repository</a> for the exercises, concepts &amp; project solution from Day2. This also shows you my failed attempts in my commit history.</p><blockquote>*Please note the link provided to the 100daysofcode bootcamp course is affiliated. I will receive a small % from each purchase.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7b818b5aef3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[100 Days of Code: Day 1]]></title>
            <link>https://medium.com/@techytish/100-days-of-code-day-1-63f129f08daa?source=rss-9da100b017f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/63f129f08daa</guid>
            <category><![CDATA[100daysofcode]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Tish H.]]></dc:creator>
            <pubDate>Wed, 08 Jun 2022 22:22:09 GMT</pubDate>
            <atom:updated>2022-06-09T20:20:24.703Z</atom:updated>
            <content:encoded><![CDATA[<p>Today is the day I begin my journey of completing this challenge #100daysofcode in Python.</p><p>I am following Dr Angela Yu’s bootcamp programme of 100 days of code using the Python programming language. I have signed the pledge form and I cant wait to develop my skills even more.</p><p>You can find a link to my GitHub repository and follow my journey at the end of this article.</p><blockquote>*100daysofcode Link: <a href="https://tidd.ly/3GNwiIt">https://tidd.ly/3GNwiIt</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dKQGeIk6EMFKbHrw" /><figcaption>Photo by <a href="https://unsplash.com/@cdr6934?utm_source=medium&amp;utm_medium=referral">Chris Ried</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Tools</h3><ul><li>GitHub — if you haven’t, create a <a href="https://github.com/">GitHub</a> account so you can create a repository and make regular commits to your projects.</li><li>IDE — I will be using <a href="https://code.visualstudio.com/download">VSCode</a>, I am familiar with this environment for coding and its free, lightweight and easy to use.</li><li>Python — make sure you have the latest version of Python installed, download <a href="https://www.python.org/downloads/">here</a>.</li></ul><h3>Exercises &amp; Concepts Learnt</h3><p>Below are a few of the concepts learnt in Day1 of the course and exercises to practice those concepts.</p><pre>printing strings</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e62f34575eed9079baea1d4e77823888/href">https://medium.com/media/e62f34575eed9079baea1d4e77823888/href</a></iframe><pre>printing strings with user inputs</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0c56daedc7bc01d39e1f6e5970ca5ae/href">https://medium.com/media/a0c56daedc7bc01d39e1f6e5970ca5ae/href</a></iframe><pre>comments</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b7bd6789cc9144d32812b8485251734/href">https://medium.com/media/1b7bd6789cc9144d32812b8485251734/href</a></iframe><pre>variables</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2dfdff6310157cba7b44d2c95b3f8ec/href">https://medium.com/media/c2dfdff6310157cba7b44d2c95b3f8ec/href</a></iframe><blockquote><em>💡</em> <strong>Tip: </strong>How to run Python scripts on the terminal in VSCode?</blockquote><ol><li>Open <strong>terminal</strong></li><li>Navigate to the directory (folder) where the <strong>.py</strong> file is in (learn basic directory commands <a href="https://dyclassroom.com/reference-linux/linux-commands-working-with-files-and-directories">here</a>)</li><li>Type <strong>python3</strong> + <strong>tab</strong> until the filename of the script you want run appears.</li><li>Hit enter on your keyboard and the script should start</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WFV-e5EOStZTdgSxD-ZXcg.png" /></figure><h3>Quiz</h3><p>Each day there is a quiz at the end but before you tackle the project. This will help test the concepts you’ve learnt and try to get you to think outside of the box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*aFeI_btkKhUn4JhUsQEDQA.png" /></figure><h3>Day 1 | Project “Band Name Generator”</h3><pre>project-band_name_generator.py</pre><p>So the Python programme to be built is essentially a name generator based on user inputs. Using the concepts learnt in Day1, the programme will make use of print statement, inputs, variables. Below you can see how the task is laid out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAWKdn7jpCepHF5x9gxJNw.png" /></figure><pre>how it looks on the terminal</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0TazRhC40D-BSZJfsD3dvQ.png" /></figure><p>Check out my <a href="https://github.com/TechyTish/100daysofcode">GitHub repository</a> for the exercises, concepts &amp; project solution from Day1. This also shows you my failed attempts in my commit history.</p><blockquote>*Please note the link provided to the 100daysofcode bootcamp course is affiliated. I will receive a small % from each purchase.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63f129f08daa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>