<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dhaval Mehta</title>
    <description>The latest articles on DEV Community by Dhaval Mehta (@dmehta83).</description>
    <link>https://dev.to/dmehta83</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1113341%2Fdae8549a-3dbe-4990-95c2-e10c4a709b4a.png</url>
      <title>DEV Community: Dhaval Mehta</title>
      <link>https://dev.to/dmehta83</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dmehta83"/>
    <language>en</language>
    <item>
      <title>Unleashing the Power of Observability: Serverless Monitoring and Logging with AWS CloudWatch - Part 2</title>
      <dc:creator>Dhaval Mehta</dc:creator>
      <pubDate>Fri, 21 Jul 2023 14:48:50 +0000</pubDate>
      <link>https://dev.to/dmehta83/unleashing-the-power-of-observability-serverless-monitoring-and-logging-with-aws-cloudwatch-part-2-3adp</link>
      <guid>https://dev.to/dmehta83/unleashing-the-power-of-observability-serverless-monitoring-and-logging-with-aws-cloudwatch-part-2-3adp</guid>
      <description>&lt;p&gt;&lt;strong&gt;Part 2: Collecting and Monitoring Serverless Metrics&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Welcome to the second part of our blog series on "Unleashing the Power of Observability: Serverless Monitoring and Logging with AWS CloudWatch." In this post, we'll focus on metrics, a critical component for understanding the performance of serverless functions. We'll cover how to enable CloudWatch metrics for AWS Lambda functions and explore the available metrics to gain valuable insights into your serverless application's behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Enabling CloudWatch Metrics for AWS Lambda Functions&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Enabling CloudWatch metrics for AWS Lambda functions is a straightforward process that allows you to start collecting valuable data about the performance of your serverless application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Using the AWS Management Console:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step 1: Go to the AWS Management Console and navigate to the Lambda service.&lt;/p&gt;

&lt;p&gt;Step 2: Select your Lambda function from the list and click on "Monitoring" in the navigation menu.&lt;/p&gt;

&lt;p&gt;Step 3: In the Monitoring tab, you'll find the option to enable CloudWatch metrics. Simply click on the "Edit" button and choose "Enable" to start collecting metrics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Using the AWS Command Line Interface (CLI):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can also enable CloudWatch metrics for your Lambda function programmatically using the AWS CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws lambda put-function-concurrency &lt;span class="nt"&gt;--function-name&lt;/span&gt; YourLambdaFunctionName &lt;span class="nt"&gt;--reserved-concurrent-executions&lt;/span&gt; 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By enabling CloudWatch metrics, you'll gain insights into essential performance metrics like the number of invocations, duration, errors, and throttles, which will help you optimize your serverless application.&lt;/p&gt;

&lt;h2&gt;
  
  
  **Exploring Available Metrics for AWS Lambda Functions
&lt;/h2&gt;

&lt;p&gt;Once you've enabled CloudWatch metrics for your Lambda function, you can explore and analyze a wealth of valuable data.**&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Using the AWS Management Console:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step 1: Go to the AWS Management Console and navigate to the CloudWatch service.&lt;/p&gt;

&lt;p&gt;Step 2: In the navigation pane, click on "Metrics."&lt;/p&gt;

&lt;p&gt;Step 3: Under "All metrics," select "AWS/Lambda" as the Namespace.&lt;/p&gt;

&lt;p&gt;Step 4: You'll see a list of available metrics for your Lambda functions, such as "Invocations," "Duration," "Errors," "Throttles," and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Using the AWS CLI:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can programmatically retrieve the available CloudWatch metrics for your Lambda functions using the AWS CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws cloudwatch list-metrics &lt;span class="nt"&gt;--namespace&lt;/span&gt; &lt;span class="s2"&gt;"AWS/Lambda"&lt;/span&gt; &lt;span class="nt"&gt;--metric-name&lt;/span&gt; &lt;span class="s2"&gt;"Invocations"&lt;/span&gt; &lt;span class="nt"&gt;--dimensions&lt;/span&gt; &lt;span class="nv"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;FunctionName,Value&lt;span class="o"&gt;=&lt;/span&gt;YourLambdaFunctionName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The metrics provided by CloudWatch will give you a comprehensive view of how your Lambda function is performing and help you identify any areas that may need improvement or optimization.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Creating Custom Metrics for AWS Lambda Functions&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In addition to the default metrics provided by CloudWatch, you can create and publish custom metrics to monitor specific aspects of your serverless application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Using the AWS SDK:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can use the AWS SDK for your preferred programming language to publish custom metrics to CloudWatch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;boto3&lt;/span&gt;

&lt;span class="n"&gt;cloudwatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'cloudwatch'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cloudwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;put_metric_data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;Namespace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'CustomMetrics'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;MetricData&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;'MetricName'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'CustomMetric'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s"&gt;'Value'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s"&gt;'Unit'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Count'&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Custom metrics allow you to track application-specific data and business metrics, enabling you to make informed decisions based on the behavior of your serverless functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this post, we focused on the importance of metrics in understanding the performance of serverless functions. We explored how to enable CloudWatch metrics for AWS Lambda functions using both the AWS Management Console and the AWS CLI. Additionally, we learned how to explore the available metrics and how to create and publish custom metrics for more tailored monitoring.&lt;/p&gt;

&lt;p&gt;In the next part of our blog series, "Centralized Logging with CloudWatch Logs," we'll delve into how to enable CloudWatch Logs for Lambda functions and effectively manage and analyze logs to gain deep insights into your serverless applications. Stay tuned for more exciting insights and practical examples on leveraging AWS CloudWatch for effective observability in your serverless architecture.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Automating AWS Batch Jobs with Amazon EventBridge Scheduler</title>
      <dc:creator>Dhaval Mehta</dc:creator>
      <pubDate>Fri, 21 Jul 2023 12:41:23 +0000</pubDate>
      <link>https://dev.to/dmehta83/automating-aws-batch-jobs-with-amazon-eventbridge-scheduler-424p</link>
      <guid>https://dev.to/dmehta83/automating-aws-batch-jobs-with-amazon-eventbridge-scheduler-424p</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Amazon EventBridge Scheduler, introduced by AWS in November 2022, is a powerful serverless scheduler that allows you to create, run, and manage tasks across various AWS services from one central, managed platform. This highly scalable service enables you to schedule millions of tasks, invoking any AWS service as a target, without the need for provisioning or managing underlying infrastructure. In this blog post, we will explore how to use EventBridge Scheduler to automate AWS Batch jobs, ensuring smooth and efficient task execution.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Amazon EventBridge Scheduler?
&lt;/h2&gt;

&lt;p&gt;Amazon EventBridge Scheduler is a serverless scheduler introduced by AWS to facilitate the easy creation, execution, and management of tasks across multiple AWS services. With support for over 200 services and more than 6,000 APIs, the scheduler allows you to configure schedules with a minimum granularity of one minute, ensuring precise control over task execution. It also offers at-least-once event delivery to targets, along with the ability to set delivery windows, retries, retention times, and dead letter queues.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does EventBridge Scheduler work?
&lt;/h2&gt;

&lt;p&gt;EventBridge Scheduler enables you to create one-time or recurring schedules, making it flexible enough to handle various use cases. Whether you need to trigger a task just once or run it periodically, EventBridge Scheduler has you covered. The scheduler requires no event bus, streamlining the process of setting up schedules and reducing complexity. Here are some key features of EventBridge Scheduler:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Quota on schedules: Up to 1 million schedules per AWS account.&lt;/li&gt;
&lt;li&gt;Event invocation throughput: Capable of supporting throughput in thousands of transactions per second (TPS).&lt;/li&gt;
&lt;li&gt;Targets: Over 270 services and more than 6,000 API actions with AWS SDK targets.&lt;/li&gt;
&lt;li&gt;Time expressions and time-zones: Supports &lt;code&gt;at()&lt;/code&gt;, &lt;code&gt;cron()&lt;/code&gt;, and &lt;code&gt;rate()&lt;/code&gt; expressions in all time-zones and with Daylight Saving Time (DST) adjustments.&lt;/li&gt;
&lt;li&gt;One-time schedules: Allows the creation of single, one-off schedules with precise execution times.&lt;/li&gt;
&lt;li&gt;Time window schedules: Enables the configuration of schedules with a time window for more flexibility.&lt;/li&gt;
&lt;li&gt;Rule quota consumption: No rule quota consumption; soft limit of 1 million schedules.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Scheduling AWS Batch Jobs with EventBridge Scheduler
&lt;/h2&gt;

&lt;p&gt;Now, let's dive into the process of automating AWS Batch jobs using Amazon EventBridge Scheduler. Below are the steps to achieve this:&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating the Required Policies
&lt;/h3&gt;

&lt;p&gt;To get started, we need to create a policy that grants the necessary permissions for the Scheduler to execute our AWS Batch job. The policy should include permissions for &lt;code&gt;"batch:SubmitJob"&lt;/code&gt;, &lt;code&gt;"batch:DescribeJobDefinitions"&lt;/code&gt;, and &lt;code&gt;"batch:DescribeJobQueues"&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# CloudFormation code snippet for creating the BatchSubmitPolicy&lt;/span&gt;
&lt;span class="na"&gt;BatchSubmitPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::IAM::ManagedPolicy&lt;/span&gt;
  &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Policy to allow Scheduler to execute AWS Batch jobs&lt;/span&gt;
    &lt;span class="na"&gt;ManagedPolicyName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;YourBatchSubmitPolicy&lt;/span&gt;
    &lt;span class="na"&gt;PolicyDocument&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;Version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2012-10-17"&lt;/span&gt;
      &lt;span class="na"&gt;Statement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Effect&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Allow'&lt;/span&gt;
          &lt;span class="na"&gt;Action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;batch:SubmitJob"&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;batch:DescribeJobDefinitions"&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;batch:DescribeJobQueues"&lt;/span&gt;
          &lt;span class="na"&gt;Resource&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;YourBatchJobDefinitionARN&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;YourBatchJobQueueARN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Creating the required role
&lt;/h3&gt;

&lt;p&gt;Next, we create an IAM role that the Scheduler will assume to execute the tasks. This role will have the previously created BatchSubmitPolicy attached.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# CloudFormation code snippet for creating the EventBridgeRole&lt;/span&gt;
&lt;span class="na"&gt;EventBridgeRole&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::IAM::Role'&lt;/span&gt;
  &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;AssumeRolePolicyDocument&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;Version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;2012-10-17&lt;/span&gt;
      &lt;span class="na"&gt;Statement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Effect&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Allow'&lt;/span&gt;
          &lt;span class="na"&gt;Principal&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;Service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;scheduler.amazonaws.com'&lt;/span&gt;
          &lt;span class="na"&gt;Action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;sts:AssumeRole'&lt;/span&gt;
    &lt;span class="na"&gt;Path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/"&lt;/span&gt;
    &lt;span class="na"&gt;ManagedPolicyArns&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;BatchSubmitPolicy&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;EventBridge role for AWS Batch job execution&lt;/span&gt;
    &lt;span class="na"&gt;RoleName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;YourEventBridgeRole&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuring the Schedule
&lt;/h3&gt;

&lt;p&gt;Now we create the EventBridge schedule, specifying the name, description, and the desired ScheduleExpression. In this example, we use a rate expression to trigger the job every 8 hours.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# CloudFormation code snippet for creating the EventSchedule&lt;/span&gt;
&lt;span class="na"&gt;EventSchedule&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::Scheduler::Schedule&lt;/span&gt;
  &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;EventBridge&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;schedule&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;to&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;trigger&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;the&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;AWS&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Batch&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;job'&lt;/span&gt;
    &lt;span class="na"&gt;FlexibleTimeWindow&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
      &lt;span class="na"&gt;Mode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OFF"&lt;/span&gt;
    &lt;span class="na"&gt;Name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;YourBatchExecSchedule&lt;/span&gt;
    &lt;span class="na"&gt;ScheduleExpression&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rate(8&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;hours)'&lt;/span&gt;
    &lt;span class="na"&gt;State&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ENABLED'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Defining the Target
&lt;/h3&gt;

&lt;p&gt;The TargetArn needs to be defined in a specific format, and in this case, we'll set it to invoke the "batch:SubmitJob" API action of AWS Batch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# CloudFormation code snippet for defining the Target&lt;/span&gt;
&lt;span class="na"&gt;Target&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
  &lt;span class="na"&gt;Arn&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;arn:aws:scheduler:::aws-sdk:batch:submitJob&lt;/span&gt;
  &lt;span class="na"&gt;RoleArn&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!GetAtt&lt;/span&gt; &lt;span class="s"&gt;EventBridgeRole.Arn&lt;/span&gt;     
  &lt;span class="na"&gt;Input&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Sub&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
    &lt;span class="s"&gt;{&lt;/span&gt;
      &lt;span class="s"&gt;"JobName": "scheduled-batch-job",&lt;/span&gt;
      &lt;span class="s"&gt;"JobDefinition": "YourBatchJobDefinitionARN",&lt;/span&gt;
      &lt;span class="s"&gt;"JobQueue": "YourBatchJobQueueARN",&lt;/span&gt;
      &lt;span class="s"&gt;"ContainerOverrides": {&lt;/span&gt;
          &lt;span class="s"&gt;"Environment": [ &lt;/span&gt;
            &lt;span class="s"&gt;{ &lt;/span&gt;
                &lt;span class="s"&gt;"Name": "LoggingLevel",&lt;/span&gt;
                &lt;span class="s"&gt;"Value": "${LoggingLevel}"&lt;/span&gt;
            &lt;span class="s"&gt;},&lt;/span&gt;
            &lt;span class="s"&gt;{&lt;/span&gt;
              &lt;span class="s"&gt;"Name": "Prefix",&lt;/span&gt;
              &lt;span class="s"&gt;"Value": "${Prefix}"&lt;/span&gt;
            &lt;span class="s"&gt;}&lt;/span&gt;
          &lt;span class="s"&gt;]&lt;/span&gt;
        &lt;span class="s"&gt;}            &lt;/span&gt;
    &lt;span class="s"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Complete CloudFormation Code
&lt;/h3&gt;

&lt;p&gt;Here's the complete CloudFormation template to create the EventBridge schedule for your AWS Batch job.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;AWSTemplateFormatVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2010-09-09"&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;CloudFormation template to create an EventBridge schedule for AWS Batch jobs&lt;/span&gt;

&lt;span class="na"&gt;Parameters&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;LoggingLevel&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;String&lt;/span&gt;
    &lt;span class="na"&gt;AllowedValues&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;NOTSET&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;DEBUG&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;INFO&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;WARNING&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;ERROR&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;CRITICAL&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;    
    &lt;span class="na"&gt;Default&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFO"&lt;/span&gt;     

  &lt;span class="na"&gt;Prefix&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;String&lt;/span&gt;
    &lt;span class="na"&gt;Default&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prefix-value"&lt;/span&gt;   

&lt;span class="na"&gt;Resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;BatchSubmitPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::IAM::ManagedPolicy&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Policy to allow Scheduler to execute AWS Batch jobs&lt;/span&gt;
      &lt;span class="na"&gt;ManagedPolicyName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;YourBatchSubmitPolicy&lt;/span&gt;
      &lt;span class="na"&gt;PolicyDocument&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;Version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2012-10-17"&lt;/span&gt;
        &lt;span class="na"&gt;Statement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Effect&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Allow'&lt;/span&gt;
            &lt;span class="na"&gt;Action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
              &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;batch:SubmitJob"&lt;/span&gt;
              &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;batch:DescribeJobDefinitions"&lt;/span&gt;
              &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;batch:DescribeJobQueues"&lt;/span&gt;
            &lt;span class="na"&gt;Resource&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;YourBatchJobDefinitionARN&lt;/span&gt;
              &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;YourBatchJobQueueARN&lt;/span&gt;

  &lt;span class="na"&gt;EventBridgeRole&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::IAM::Role'&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;AssumeRolePolicyDocument&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;Version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;2012-10-17&lt;/span&gt;
        &lt;span class="na"&gt;Statement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Effect&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Allow'&lt;/span&gt;
            &lt;span class="na"&gt;Principal&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;Service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;scheduler.amazonaws.com'&lt;/span&gt;
            &lt;span class="na"&gt;Action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;sts:AssumeRole'&lt;/span&gt;
      &lt;span class="na"&gt;Path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/"&lt;/span&gt;
      &lt;span class="na"&gt;ManagedPolicyArns&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;BatchSubmitPolicy&lt;/span&gt;
      &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;EventBridge role for AWS Batch job execution&lt;/span&gt;
      &lt;span class="na"&gt;RoleName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;YourEventBridgeRole&lt;/span&gt;

  &lt;span class="na"&gt;EventSchedule&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::Scheduler::Schedule&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
      &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;EventBridge&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;schedule&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;to&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;trigger&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;the&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;AWS&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Batch&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;job'&lt;/span&gt;
      &lt;span class="na"&gt;FlexibleTimeWindow&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
        &lt;span class="na"&gt;Mode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OFF"&lt;/span&gt;
      &lt;span class="na"&gt;Name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;YourBatchExecSchedule&lt;/span&gt;
      &lt;span class="na"&gt;ScheduleExpression&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rate(8&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;hours)'&lt;/span&gt;
      &lt;span class="na"&gt;State&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ENABLED'&lt;/span&gt;
      &lt;span class="na"&gt;Target&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
        &lt;span class="na"&gt;Arn&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;arn:aws:scheduler:::aws-sdk:batch:submitJob&lt;/span&gt;
        &lt;span class="na"&gt;RoleArn&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!GetAtt&lt;/span&gt; &lt;span class="s"&gt;EventBridgeRole.Arn&lt;/span&gt;     
        &lt;span class="na"&gt;Input&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Sub&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"JobName": "scheduled-batch-job",&lt;/span&gt;
            &lt;span class="s"&gt;"JobDefinition": "YourBatchJobDefinitionARN",&lt;/span&gt;
            &lt;span class="s"&gt;"JobQueue": "YourBatchJobQueueARN",&lt;/span&gt;
            &lt;span class="s"&gt;"ContainerOverrides": {&lt;/span&gt;
                &lt;span class="s"&gt;"Environment": [ &lt;/span&gt;
                  &lt;span class="s"&gt;{ &lt;/span&gt;
                      &lt;span class="s"&gt;"Name": "LoggingLevel",&lt;/span&gt;
                      &lt;span class="s"&gt;"Value": "${LoggingLevel}"&lt;/span&gt;
                  &lt;span class="s"&gt;},&lt;/span&gt;
                  &lt;span class="s"&gt;{&lt;/span&gt;
                    &lt;span class="s"&gt;"Name": "Prefix",&lt;/span&gt;
                    &lt;span class="s"&gt;"Value": "${Prefix}"&lt;/span&gt;
                  &lt;span class="s"&gt;}&lt;/span&gt;
                &lt;span class="s"&gt;]&lt;/span&gt;
              &lt;span class="s"&gt;}            &lt;/span&gt;
          &lt;span class="s"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Amazon EventBridge Scheduler offers a powerful and flexible solution for automating tasks across various AWS services. In this blog post, we explored how to use EventBridge Scheduler to schedule and trigger AWS Batch jobs. By following the steps outlined in this guide, you can efficiently manage your tasks and improve operational efficiency.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-targets-universal.html"&gt;Amazon EventBridge Scheduler Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-targets-universal.html#supported-universal-targets"&gt;Supported Universal Targets for EventBridge Scheduler&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/batch/latest/APIReference/API_SubmitJob.html"&gt;AWS Batch API Reference - Submit Job&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html"&gt;AWS CloudFormation - AWS::Scheduler::Schedule Resource Type&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>serverless</category>
      <category>eventbridge</category>
      <category>batch</category>
      <category>cloudformation</category>
    </item>
    <item>
      <title>Unleashing the Power of Observability: Serverless Monitoring and Logging with AWS CloudWatch - Part 1</title>
      <dc:creator>Dhaval Mehta</dc:creator>
      <pubDate>Sun, 09 Jul 2023 17:08:52 +0000</pubDate>
      <link>https://dev.to/dmehta83/unleashing-the-power-of-observability-serverless-monitoring-and-logging-with-aws-cloudwatch-1gjm</link>
      <guid>https://dev.to/dmehta83/unleashing-the-power-of-observability-serverless-monitoring-and-logging-with-aws-cloudwatch-1gjm</guid>
      <description>&lt;p&gt;&lt;strong&gt;Part 1: Introduction to AWS CloudWatch&lt;/strong&gt;&lt;br&gt;
Welcome to the first part of our blog series on "Unleashing the Power of Observability: Serverless Monitoring and Logging with AWS CloudWatch." In this introductory post, we'll explore the fundamental concepts and capabilities of AWS CloudWatch, a powerful monitoring and observability service offered by Amazon Web Services. By the end of this post, you'll have a clear understanding of what CloudWatch is and how it can benefit your serverless applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is AWS CloudWatch?&lt;/strong&gt;&lt;br&gt;
AWS CloudWatch is a fully managed monitoring and observability service that provides real-time insights into the performance, health, and behavior of your AWS resources and applications. It enables you to collect and monitor metrics, collect and analyze logs, set alarms, and create dashboards to gain valuable operational insights.&lt;/p&gt;

&lt;p&gt;CloudWatch offers a centralized platform for monitoring all your AWS services, making it easier to identify and resolve issues, optimize resource utilization, and ensure the overall efficiency of your cloud-based applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features of AWS CloudWatch&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1. Metrics&lt;/strong&gt;&lt;br&gt;
Metrics are fundamental to monitoring the performance of your AWS resources and services. CloudWatch allows you to collect, store, and visualize various metrics for different AWS services. These metrics provide crucial data points such as CPU utilization, network traffic, request counts, latency, and more. You can use these metrics to gain insights into the behavior of your resources and make informed decisions to improve performance and efficiency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Code Snippet: Enabling CloudWatch Metrics for an AWS Lambda Function&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;boto3&lt;/span&gt;

&lt;span class="c1"&gt;# Enable CloudWatch metrics for an AWS Lambda function
&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'lambda'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;put_function_concurrency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;FunctionName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'YourLambdaFunctionName'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ReservedConcurrentExecutions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Logs&lt;/strong&gt;&lt;br&gt;
CloudWatch Logs allows you to collect and store logs from various AWS services and applications. You can use CloudWatch Logs to troubleshoot issues, monitor application events, and analyze log data efficiently. With support for real-time log streaming, you can stay on top of critical events and identify potential problems before they escalate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Code Snippet: Configuring CloudWatch Logs for an AWS Lambda Function&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;logging&lt;/span&gt;

&lt;span class="c1"&gt;# Configure CloudWatch logging for an AWS Lambda function
&lt;/span&gt;&lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getLogger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setLevel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;INFO&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StreamHandler&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;addHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Alarms&lt;/strong&gt;&lt;br&gt;
CloudWatch Alarms enable you to set up automated actions based on predefined thresholds for specific metrics. When a metric breaches the defined threshold, CloudWatch can trigger notifications or execute actions such as sending an SNS notification or performing an Auto Scaling action.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Code Snippet: Setting Up a CloudWatch Alarm for High CPU Utilization&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;boto3&lt;/span&gt;
&lt;span class="c1"&gt;# Create a CloudWatch Alarm
&lt;/span&gt;&lt;span class="n"&gt;cloudwatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'cloudwatch'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;cloudwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;put_metric_alarm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;AlarmName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'YourAlarmName'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ComparisonOperator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'GreaterThanThreshold'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;EvaluationPeriods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;MetricName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'CPUUtilization'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Namespace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'AWS/EC2'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Period&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Statistic&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'Average'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Threshold&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;80.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ActionsEnabled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;AlarmDescription&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'Alarm when CPU exceeds 80%'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;AlarmActions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'arn:aws:sns:us-east-1:123456789012:YourSNSTopic'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Dashboards&lt;/strong&gt;&lt;br&gt;
CloudWatch Dashboards allow you to create custom visualizations of your metrics and logs in a centralized location. You can design dashboards with various widgets like line charts, bar charts, and text widgets, providing you with a consolidated view of the health and performance of your AWS resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Event Rules&lt;/strong&gt;&lt;br&gt;
CloudWatch Event Rules help you automate responses to operational changes within your AWS environment. By defining rules based on events or scheduled tasks, you can trigger actions like invoking a Lambda function, publishing to an SNS topic, or sending data to Kinesis Data Streams.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this introductory post, we explored AWS CloudWatch and its essential features, which include metrics, logs, alarms, dashboards, and event rules. As a monitoring and observability service, CloudWatch empowers you to gain real-time insights into your AWS resources and applications, ensuring their optimal performance and reliability.&lt;/p&gt;

&lt;p&gt;In the next part of this blog series, we'll dive deeper into Monitoring Serverless Applications with CloudWatch Metrics, where we'll explore how to enable CloudWatch metrics for AWS Lambda functions and leverage these metrics to monitor and optimize your serverless applications. Stay tuned for more exciting insights and practical examples on leveraging AWS CloudWatch for effective observability in your serverless architecture.&lt;/p&gt;

</description>
      <category>monitoring</category>
      <category>serverless</category>
      <category>cloudwatch</category>
      <category>aws</category>
    </item>
    <item>
      <title>Streamlining Software Delivery: Mastering Serverless CI/CD Pipelines with AWS</title>
      <dc:creator>Dhaval Mehta</dc:creator>
      <pubDate>Sun, 09 Jul 2023 17:04:16 +0000</pubDate>
      <link>https://dev.to/dmehta83/streamlining-software-delivery-mastering-serverless-cicd-pipelines-with-aws-4k5e</link>
      <guid>https://dev.to/dmehta83/streamlining-software-delivery-mastering-serverless-cicd-pipelines-with-aws-4k5e</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction:&lt;/strong&gt;&lt;br&gt;
Continuous Integration and Continuous Deployment (CI/CD) pipelines are essential for automating the software delivery process and ensuring fast and reliable releases. In this blog post, we'll explore how to build serverless CI/CD pipelines using AWS services. We'll leverage AWS CodePipeline, AWS CodeBuild, and AWS Lambda to create a fully automated pipeline that builds, tests, and deploys our applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;br&gt;
To follow along with this tutorial, you'll need:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An AWS account&lt;/li&gt;
&lt;li&gt;Basic knowledge of AWS services, specifically AWS CodePipeline, AWS CodeBuild, and AWS Lambda&lt;/li&gt;
&lt;li&gt;A sample application (e.g., a Node.js application hosted on GitHub)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Set up the CodePipeline&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, let's create the CodePipeline that will orchestrate our CI/CD process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the AWS Management Console and open the AWS CodePipeline service.&lt;/li&gt;
&lt;li&gt;Click on "Create pipeline" to start creating a new pipeline.
Provide a pipeline name and select your source provider (e.g., GitHub).&lt;/li&gt;
&lt;li&gt;Connect to your GitHub repository and choose the branch to monitor for changes.&lt;/li&gt;
&lt;li&gt;Configure the build stage by selecting AWS CodeBuild as the build provider and specifying the build configuration.&lt;/li&gt;
&lt;li&gt;Set up the deployment stage to deploy your application to the desired environment (e.g., AWS Elastic Beanstalk or AWS Lambda).&lt;/li&gt;
&lt;li&gt;Review the pipeline settings and click on "Create pipeline" to create the pipeline.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create the CodeBuild Project&lt;/strong&gt;&lt;br&gt;
Next, let's create a CodeBuild project that will compile and test our application:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the AWS CodeBuild service in the AWS Management Console.&lt;/li&gt;
&lt;li&gt;Click on "Create build project" to create a new CodeBuild project.&lt;/li&gt;
&lt;li&gt;Provide a project name and select the source provider (e.g., GitHub).&lt;/li&gt;
&lt;li&gt;Connect to your GitHub repository and choose the branch to build.&lt;/li&gt;
&lt;li&gt;Configure the build environment with the desired runtime and build specifications.&lt;/li&gt;
&lt;li&gt;Define the build specifications in the buildspec.yml file, which includes build steps, tests, and artifacts.&lt;/li&gt;
&lt;li&gt;Review the project settings and click on "Create build project" to create the project.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Set up Deployment with AWS Lambda&lt;/strong&gt;&lt;br&gt;
In this step, we'll configure AWS Lambda as our deployment provider to deploy the application:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the AWS Lambda service in the AWS Management Console.&lt;/li&gt;
&lt;li&gt;Click on "Create function" to create a new Lambda function.&lt;/li&gt;
&lt;li&gt;Select the desired runtime (e.g., Node.js) and provide a function name.&lt;/li&gt;
&lt;li&gt;Choose an appropriate IAM role for the Lambda function with the necessary permissions.&lt;/li&gt;
&lt;li&gt;Write the deployment logic in the Lambda function using the desired deployment approach (e.g., AWS SDK, AWS CLI, or a deployment framework like Serverless Framework).&lt;/li&gt;
&lt;li&gt;Review the function settings and click on "Create function" to create the Lambda function.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Configure CodePipeline to Use AWS Lambda for Deployment&lt;/strong&gt;&lt;br&gt;
Now, let's configure CodePipeline to use the Lambda function for deployment:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the AWS CodePipeline service in the AWS Management Console.&lt;/li&gt;
&lt;li&gt;Select your pipeline and click on "Edit" to modify the pipeline configuration.&lt;/li&gt;
&lt;li&gt;Navigate to the deployment stage and choose "AWS Lambda" as the deployment provider.&lt;/li&gt;
&lt;li&gt;Specify the Lambda function name and any additional configuration settings.&lt;/li&gt;
&lt;li&gt;Save the pipeline changes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
In this blog post, we explored how to build serverless CI/CD pipelines using AWS services. We set up an end-to-end pipeline using AWS CodePipeline, AWS CodeBuild, and AWS Lambda. This pipeline automatically builds, tests, and deploys our application whenever changes are pushed to the source repository. With serverless CI/CD pipelines, you can ensure fast and reliable software delivery in a scalable and cost-efficient manner.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Extending CloudFormation's Power: Creating Custom Resources for Enhanced AWS Resource Management</title>
      <dc:creator>Dhaval Mehta</dc:creator>
      <pubDate>Tue, 04 Jul 2023 17:38:24 +0000</pubDate>
      <link>https://dev.to/dmehta83/extending-cloudformations-power-creating-custom-resources-for-enhanced-aws-resource-management-3o61</link>
      <guid>https://dev.to/dmehta83/extending-cloudformations-power-creating-custom-resources-for-enhanced-aws-resource-management-3o61</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction:&lt;/strong&gt;&lt;br&gt;
CloudFormation templates are powerful tools for programmatically provisioning AWS resources. While they provide a wide range of predefined resources and templates, there are situations that call for additional custom actions. In this blog post, we will explore the process of creating and utilizing custom resources in CloudFormation to enhance your AWS resource management.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Do We Need Custom Resources?&lt;/strong&gt;&lt;br&gt;
CloudFormation templates excel at creating AWS resources through code. However, there are instances where you may require specific actions to be performed on the created resources. These actions might involve tasks such as creating directories within newly generated buckets, configuring OpenSearch indexes, inserting essential data into databases, or cleaning up resources when shutting down infrastructure. Custom resources offer the means to extend CloudFormation's capabilities, empowering you to address these specialized requirements seamlessly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Custom Resource: Step-by-Step Guide&lt;/strong&gt;&lt;br&gt;
To create a custom resource using CloudFormation, follow these three steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; &lt;strong&gt;Create a Role for the Lambda Function&lt;/strong&gt;&lt;br&gt;
Start by creating a role that the Lambda function we will use. This role should have the necessary permissions to perform the required actions. In the example below, we grant the Lambda function permissions for executing code and accessing S3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CustomLambdaRole:
  Type: AWS::IAM::Role
  Properties:
    AssumeRolePolicyDocument:
      Version: '2012-10-17'
      Statement:
        - Effect: Allow
          Principal:
            Service:
              - lambda.amazonaws.com
          Action:
            - sts:AssumeRole
    Path: "/"
    ManagedPolicyArns:
      - "arn:aws:iam::aws:policy/AWSLambdaExecute"
      - "arn:aws:iam::aws:policy/AmazonS3FullAccess"
    Description: "Custom Lambda Role"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Create the Lambda Function&lt;/strong&gt;&lt;br&gt;
Next, create the Lambda function itself using CloudFormation. The example below demonstrates how to define the function and its properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CustomFunction:
  Type: AWS::Lambda::Function
  Properties: 
    Architectures: 
      - "x86_64"
    Code:
      ZipFile: |
        import boto3
        import json
        import os
        import urllib3

        # Retrieve Environment Variables
        S3Bucket=os.environ["S3Bucket"]

        http = urllib3.PoolManager()
        SUCCESS = "SUCCESS"
        FAILED = "FAILED"

        def lambda_handler(event, context):
            # Retrieve parameters
            dirs = event['ResourceProperties']['dirs']
            response_data = {}
            try:
                if event['RequestType'] in ('Create', 'Update'):
                    createUpdateEvent(dirs)
                elif event['RequestType'] == 'Delete':
                    deleteEvent()

                # Everything OK... send the signal back                
                send(event,
                    context,
                    SUCCESS,
                    response_data)

            except Exception as e:
                response_data['Data'] = str(e)
                send(event,
                    context,
                    FAILED,
                    response_data)

        def createUpdateEvent(dirs):
            s_3 = boto3.client('s3')
            for dir_name in dirs:
                print("Creating: ", str(dir_name))
                s_3.put_object(Bucket=S3Bucket, Key=(dir_name + '/'))

        def deleteEvent():
            print("Deleting S3 content...")
            b_operator = boto3.resource('s3')
            b_operator.Bucket(str(S3Bucket)).objects.all().delete()

        def send(event, context, responseStatus, responseData, physicalResourceId=None, noEcho=False):
            responseUrl = event['ResponseURL']
            print(responseUrl)

            responseBody = {
                'Status': responseStatus,
                'Reason': 'See the details in CloudWatch Log Stream: ' + context.log_stream_name,
                'PhysicalResourceId': physicalResourceId or context.log_stream_name,
                'StackId': event['StackId'],
                'RequestId': event['RequestId'],
                'LogicalResourceId': event['LogicalResourceId'],
                'NoEcho': noEcho,
                'Data': responseData
            }

            json_responseBody = json.dumps(responseBody)

            print("Response body:\n" + json_responseBody)

            headers = {
                'content-type': '',
                'content-length': str(len(json_responseBody))
            }

            try:
                response = http.request('PUT', responseUrl, body=json_responseBody.encode('utf-8'), headers=headers)
                print("Status code: " + response.reason)

            except Exception as e:
                print("send(..) failed executing requests.put(..): " + str(e))

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Define the Custom Resource&lt;/strong&gt;&lt;br&gt;
Finally, define the custom resource itself in the CloudFormation template. Use the following code snippet as a reference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CustomResource:
  Type: Custom::CustomResource
  Properties:
    ServiceToken: !GetAtt CustomFunction.Arn
    dirs: !Ref Dirs

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Creating Parameters for the Custom Resource&lt;/strong&gt;&lt;br&gt;
To make the custom resource more flexible, you can add parameters to the CloudFormation template. In this example, we create a parameter named "Dirs" to specify a comma-delimited list of directories to be created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Parameters:
  Dirs:
    Description: "Comma-delimited list of directories to create."
    Type: CommaDelimitedList
    Default: test-dir

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Executing this updated CloudFormation template will create an S3 bucket and automatically create a folder within that bucket as part of your infrastructure setup. You can customize the directory names by providing a comma-delimited list of values for the "Dirs" parameter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
Custom resources in CloudFormation offer a flexible way to extend the provisioning capabilities of AWS resources. By following the steps outlined in this blog post and using the updated Lambda code, you can create custom resources and seamlessly integrate them into your CodePipeline workflows. Whether it's setting up additional resources, performing specific actions, or cleaning up resources, custom resources provide a powerful solution to meet your specific requirements.&lt;/p&gt;

</description>
      <category>cloudformation</category>
      <category>customresource</category>
      <category>serverless</category>
      <category>codepipeline</category>
    </item>
  </channel>
</rss>
