<?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: Sanjeeb Mohapatra</title>
    <description>The latest articles on DEV Community by Sanjeeb Mohapatra (@sanjeeb2017).</description>
    <link>https://dev.to/sanjeeb2017</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%2F1010862%2F022e3a9c-eef0-4773-b598-362c0a9b79e7.png</url>
      <title>DEV Community: Sanjeeb Mohapatra</title>
      <link>https://dev.to/sanjeeb2017</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanjeeb2017"/>
    <language>en</language>
    <item>
      <title>Blog -3-Data Engineering – AWS S3 space monitoring – Storage Lens</title>
      <dc:creator>Sanjeeb Mohapatra</dc:creator>
      <pubDate>Fri, 10 Mar 2023 18:51:35 +0000</pubDate>
      <link>https://dev.to/sanjeeb2017/blog-3-data-engineering-aws-s3-cost-monitoring-storage-lens-b66</link>
      <guid>https://dev.to/sanjeeb2017/blog-3-data-engineering-aws-s3-cost-monitoring-storage-lens-b66</guid>
      <description>&lt;h2&gt;
  
  
  Data Engineering – AWS S3 cost monitoring – Storage Lens
&lt;/h2&gt;

&lt;p&gt;Amazon S3 is an object storage service and one of the most popular services in AWS which offers of industry-leading scalability, data availability, security, and performance. Organizations can store and retrieve any amount of data from anywhere.&lt;/p&gt;

&lt;p&gt;If an organization is using aws for their cloud service, AWS S3 is one of prefer storage solution. Some of the use cases of S3 are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build an Enterprise Data Lake &lt;/li&gt;
&lt;li&gt;Create a Disaster Recovery System for back up and restore data.&lt;/li&gt;
&lt;li&gt;Archive cold data for a long period to meet regulatory requirements&lt;/li&gt;
&lt;li&gt;Host a static website.&lt;/li&gt;
&lt;li&gt;Integrated with many cloud native solutions to provide storage option.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While you are store unlimited amount of data in S3, it is very important to monitor the storage of S3 and number of objects in S3 buckets. At end of the day every object storage occurred a cost. Organizations may not be able to quantify the storage cost when they have GB, TB data but when the data volume grow to PB’s S3 cost will be high.&lt;/p&gt;

&lt;p&gt;For example, when you store 10 PB data (for big enterprise scale applications like data lake, lake house etc)  , you have to give 220K USD for UK region for storage. So it is very important to understand the usage of S3 bucket.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OajbEZmu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z6mrt06o2ruaj9g4gs0r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OajbEZmu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z6mrt06o2ruaj9g4gs0r.png" alt="Image description" width="800" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AWS S3 have a feature called “Storage lens” where you can create your own custom dashboard and monitor the usage of S3 objects. In this blog, we will create a dashboard using storage lens and see how it work.&lt;br&gt;
To do the same. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on S3 in AWS management console. You can see the overall utilization of all your S3 buckets.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KGYcMaBp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x6jzs0038zwrpd61a6hv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KGYcMaBp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x6jzs0038zwrpd61a6hv.png" alt="Image description" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To create a Dashboard, click on the storage lens in the left panel. Click on Dashboard&lt;/li&gt;
&lt;li&gt;Click on Create Dashboard&lt;/li&gt;
&lt;li&gt;Give the below details&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Dashboard Name:  in this case we give the name as s3-bucket-usage-monitor&lt;/li&gt;
&lt;li&gt;Home Region : Select the appropriate region, for us it is London region which is eu-west-2&lt;/li&gt;
&lt;li&gt;Select Status as enable so that we can see the status of the dashboard.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---_MD3ISX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kupjj1lkb5bf8a5iocmh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---_MD3ISX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kupjj1lkb5bf8a5iocmh.png" alt="Image description" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For Dashboard Scope, if you are having objects across regions, you can select the region, in our case we ONLY select London region as all our objects are store in London region and include all buckets in the region.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3NW7JGF0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nez5nrj4pa3w8u0aue8e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3NW7JGF0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nez5nrj4pa3w8u0aue8e.png" alt="Image description" width="670" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the metrics section, select the Free metrices. A lot of key metrices are available under free metrices and that is more than enough to monitor usages of S3 buckets.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LIAZo_VC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgr14myxdwkbh3l75uad.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LIAZo_VC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgr14myxdwkbh3l75uad.png" alt="Image description" width="800" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can export these metrices to an S3 path for further analytical usages, for our case we disabled this option. Finally click create dashboard.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I-NKTvLd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bc2rr8txt60pv4fa3ay5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I-NKTvLd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bc2rr8txt60pv4fa3ay5.png" alt="Image description" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It will take 48 hours to have the charts ready.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iSAIxg5y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/svprnep3ckvpgav4pmsk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iSAIxg5y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/svprnep3ckvpgav4pmsk.png" alt="Image description" width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, AWS created a lens for you ( which cover all regions), if you want to use the default dashboard, that is fine as well. For any custom requirements like specific region or any rule we can create custom dashboard as well. Sample charts from default dashboard is :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F5YWct_q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4ivpwhk486vt81y5i3k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F5YWct_q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4ivpwhk486vt81y5i3k.png" alt="Image description" width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick Tips:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Once you understood the usages, you can see which critical data is require for your use case and access pattern. If there are buckets and folders access pattern is unknown, better to use S3 intelligent tiering for cost saving.&lt;/li&gt;
&lt;li&gt;Many organizations and enable bucket versioning so that they can avoid the accidental deletion of the object, however ONLY critical data objects (which is difficult to recreate, scripts folder) versioning make sense. But use cases like Data lake when you are getting source data and processed the data and move to archive, you really DO NOT need versioning to the staging bucket.&lt;/li&gt;
&lt;li&gt;For files which needs to be stored for long term, better to define a life cycle management to Glacier storage, this can be set it up using Life cycle management policy. &lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>awscommunity</category>
      <category>aws</category>
      <category>awscommunitybuilder</category>
    </item>
    <item>
      <title>Blog -2 :AWS Data Engineering: Audit Logs Enablement in Redshift and write to S3</title>
      <dc:creator>Sanjeeb Mohapatra</dc:creator>
      <pubDate>Sat, 25 Feb 2023 10:22:12 +0000</pubDate>
      <link>https://dev.to/sanjeeb2017/blog-2-aws-data-engineering-audit-logs-enablement-in-redshift-and-write-to-s3-3c0o</link>
      <guid>https://dev.to/sanjeeb2017/blog-2-aws-data-engineering-audit-logs-enablement-in-redshift-and-write-to-s3-3c0o</guid>
      <description>&lt;p&gt;Amazon Redshift is a columnar, fully managed cloud data warehouse service in AWS eco system. It used in executing complex, analytical queries on large volume of data sets via MPP (Massive Parallel Processing) architecture. The volume of data can be Giga bytes of Peta bytes. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important Key features for Redshift:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It supports virtually unlimited concurrent users for different workloads, such as BI/dashboard reporting, data ingestion, and adhoc data analysis. &lt;/li&gt;
&lt;li&gt;It also monitors user workloads and uses machine learning (ML) to find ways to improve the physical layout of data to further optimize query speeds.&lt;/li&gt;
&lt;li&gt;Amazon Redshift supports industry-leading security to protect your data in transit and at rest. It is compliant with SOC1, SOC2, SOC3, and PCI DSS Level 1 requirements.&lt;/li&gt;
&lt;li&gt;Both structure and semi structure data can be processed, analysed using Amazon redshift. It supports ORC, Parquet, JSON, CSV, Avro format files.&lt;/li&gt;
&lt;li&gt;Amazon Redshift is a fully managed service, user do not worry about tasks such as installing, patching, or updating software and only focus on resources on generating business value rather than maintaining infrastructure.&lt;/li&gt;
&lt;li&gt;It flexibly manages workload priorities so that short, fast-running queries won't get stuck in queues behind long-running queries.&lt;/li&gt;
&lt;li&gt;It Monitors user workloads and uses sophisticated algorithms to find ways to improve the physical layout of data to optimize query speeds&lt;/li&gt;
&lt;li&gt;Amazon redshift has the flexibility to connect different BI tools like QuickSight, Tableau, Power BI and Analytical tools like Jupyter notebook.&lt;/li&gt;
&lt;li&gt;It is fault tolerant which helped in enhance the reliability of your data warehouse cluster with features such as continuous monitoring of cluster health and automatic re-replication of data from failed drives and node replacement as necessary.&lt;/li&gt;
&lt;li&gt;Using Amazon Redshift Spectrum, user can efficiently query and retrieve structured and semi-structured data from files in Amazon Simple Storage Service (Amazon S3) and no need to load the data into Amazon Redshift tables.&lt;/li&gt;
&lt;li&gt;AWS data exchange can be used along with AWS Redshift to load and query third party data sources.&lt;/li&gt;
&lt;li&gt;Amazon Redshift ML can be used to create, train, and apply ML models with standard SQL.&lt;/li&gt;
&lt;li&gt;Redshift integrates well with AWS services to move, transform and load data quickly and reliably (for example: S3, Dyanmo DB, EMR, EC2, Data Pipeline etc )&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this blog, we are going to discuss the below problem statement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Statement:&lt;/strong&gt; One of the leading financial companies is planning to use AWS Redshift for their data warehouse. They must align with below compliance requirements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Track all audit logs of Redshift cluster
There are 3 types of audit logs available in Redshift.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Connection log – Logs authentication attempts, connections, and disconnections.&lt;/li&gt;
&lt;li&gt;User log – Logs information about changes to database user definitions.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;User activity log – Logs each query before it's run on the database.&lt;/p&gt;

&lt;p&gt;The connection and user logs are useful for security checks, it provides detail on which user is connecting to Redshift cluster, User IP address, connection time etc. The user activity log is useful primarily for troubleshooting purposes. It tracks information about the types of queries that both the users and the system perform in the database. The user activity logs captured the all user activity details like query fired by user, user id and record time details.&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Note: ( From Aws documentation)&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The connection log, user log, and user activity log are enabled together by using the AWS Management Console, the Amazon Redshift API Reference, or the AWS Command Line Interface (AWS CLI). For the user activity log, you must also enable the enable_user_activity_logging database parameter. If you enable only the audit logging feature, but not the associated parameter, the database audit logs log information for only the connection log and user log, but not for the user activity log. The enable_user_activity_logging parameter is not enabled (false) by default. You can set it to true to enable the user activity log. &lt;em&gt;In this demo we are enable the logging from AWS management console and not considered the user activity log as we are not created in custom parameter group.&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Need to store audit logs securely i.e encryption at rest.&lt;/li&gt;
&lt;li&gt;Need to store audit logs for specific time. Retention policy for the audit log is 6 months.&lt;/li&gt;
&lt;li&gt;A details analytics reports needs to derive from Audit log on Monthly basis.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s jump into the lab.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step -1: Create Redshift IAM role which will have access to have access to S3.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Login to AWS Management Console. Search IAM in the aws search bar. Click on IAM&lt;/li&gt;
&lt;li&gt;Click on Roles. &lt;/li&gt;
&lt;li&gt;Click create role.&lt;/li&gt;
&lt;li&gt;Select Trusted entity type as AWS services&lt;/li&gt;
&lt;li&gt;Under Use case tab, search for Redshift and click Next&lt;/li&gt;
&lt;li&gt;In the permission policy, search of S3 and select Amazon S3 full access (Note – It is NOT best practice to give full permission in IAM, for our demo we selected full permission, in prod workloads, better to follow least privilege principles) and click Next.&lt;/li&gt;
&lt;li&gt;Give the name of the role, description and click create role&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vqqanhkU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m83ju2b582lwwcpzidc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vqqanhkU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m83ju2b582lwwcpzidc1.png" alt="Image description" width="602" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cVgvqEel--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwrg9uxao9gvy0taeazs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cVgvqEel--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwrg9uxao9gvy0taeazs.png" alt="Image description" width="602" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step -2: Create and configure a Redshift cluster&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To create a Redshift Cluster, search Redshift in the aws console search bar.&lt;/li&gt;
&lt;li&gt;Click on create cluster&lt;/li&gt;
&lt;li&gt;Give the name of the cluster under cluster identifier.&lt;/li&gt;
&lt;li&gt;We selected the production option to have more configuration, however you can choose free tier eligible as well for demo. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O2AMTSnH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xg2n2kn5usg07cumapua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O2AMTSnH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xg2n2kn5usg07cumapua.png" alt="Image description" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select “I’II” option to select the cluster type. This will enable to configure the cluster customize approach. We selected the Node type as dc2.large ( Note – This is NOT under free tier and there will be some cost involved in this case). For our demo purpose, we select the number of nodes as 1 but in real production cases number of nodes will always be greater than 1 to have a master and slave configuration.&lt;/li&gt;
&lt;li&gt;Select the sample data so that by default Redshift will load sample data for you, this will enable to run some sample query and see the results quickly.&lt;/li&gt;
&lt;li&gt;Under Database configuration, give the admin user and password. This user credentials are required to login Redshift cluster and set up other users afterwards.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FqHowPE1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3vdt3elmyhh1uzz4zr6r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FqHowPE1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3vdt3elmyhh1uzz4zr6r.png" alt="Image description" width="602" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Under Associated IAM role, select Associate IAM role, select the IAM role which we created in step-1 and click on Associate IAM role.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mkf0I_E4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nooc79jxldexqucxkct3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mkf0I_E4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nooc79jxldexqucxkct3.png" alt="Image description" width="602" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Additional configurations, select the default option. We will configure the audit logging once the cluster is created. Click create cluster to create the cluster&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vRl09men--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3z3npxdrbxbrz0kulu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vRl09men--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3z3npxdrbxbrz0kulu9.png" alt="Image description" width="602" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To see the cluster creation status, click on the cluster on the left panel, click cluster and under cluster, you can see the cluster is under creating status.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8AUK-jb0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xrjq9hhdw88dg6hmy5k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8AUK-jb0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xrjq9hhdw88dg6hmy5k.png" alt="Image description" width="602" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Once the cluster is configured correctly, you can see the cluster status changed to Available.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zBpB2urL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k81jh2c58apsbhru5pm0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zBpB2urL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k81jh2c58apsbhru5pm0.png" alt="Image description" width="602" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To enable the audit logging, select the cluster, Go to the properties tab and under database configuration, select edit audit logging. Select turn on and select the bucket and prefix where you want to store your audit logs and click save changes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_P1NjlJe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4z26gs19orw18gpzl0sw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_P1NjlJe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4z26gs19orw18gpzl0sw.png" alt="Image description" width="602" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fmelwG2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pzhp02mx2ebu41ayb9y9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fmelwG2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pzhp02mx2ebu41ayb9y9.png" alt="Image description" width="602" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PAnavGX3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m4t72392lhirv3wmrxle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PAnavGX3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m4t72392lhirv3wmrxle.png" alt="Image description" width="599" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Once you have enabled the audit logging, you can see the details under database configuration.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4N6f1JOk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vj7qxgksgjgn7c1wiu15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4N6f1JOk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vj7qxgksgjgn7c1wiu15.png" alt="Image description" width="602" height="258"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To connect Redshift cluster and run queries, you can install client tool and download the redshift driver from aws redshift console or there is a query editor available in Redshift console and you can connect directly to Redshift database from the query editor. Click on the Query editor v2, it will open a new tab where you can get an query editor to run some sample query.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XGkcxiZO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bknnq16v6vnz585ae34t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XGkcxiZO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bknnq16v6vnz585ae34t.png" alt="Image description" width="602" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Since we have already selected to load some sample data during the creation of Redshift cluster, select the Redshift cluster, select dev database, select public, select Tables and double click any table to have the select statement in the execute command window. Run the sql statement and see the result.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O02q0Wzg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xll2hpohmykicbsi97m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O02q0Wzg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xll2hpohmykicbsi97m.png" alt="Image description" width="602" height="285"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Once you performed some actions like selecting some record, check the table count, you can see analyze the audit log file which is generated under s3.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xBH_iamW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tex9ghr6dlkl0eeqlk6d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xBH_iamW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tex9ghr6dlkl0eeqlk6d.png" alt="Image description" width="602" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To see the log file, you can download the file locally and open it any editor, one sample snapshot for connection log is &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sZVJvBly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sspp3or0y3pfwij3ls6u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sZVJvBly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sspp3or0y3pfwij3ls6u.png" alt="Image description" width="602" height="122"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step -3: Define a Life cycle rule on S3 bucket (audit log) and remove files older than 6 months.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To ensure all our audit logs are stored in encrypted at rest, The S3 bucket is encrypted by default (This is a new feature introduced by AWS recently, no action is required from user side). You can see it by navigating to the bucket, click properties, check the default encryption.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J50pOLd9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gjffpp4xh8klt84bt8nh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J50pOLd9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gjffpp4xh8klt84bt8nh.png" alt="Image description" width="602" height="109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To ensure old log files are deleted automatically after 6 months, we will define a S3 life cycle management rule which will delete the files which are created 6 months back. To do the same, navigate to S3 bucket, click on Management, click on Create a life cycle rule.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--68lmAedb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1om0p4xegl0wa427082d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--68lmAedb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1om0p4xegl0wa427082d.png" alt="Image description" width="602" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. Give the life cycle rule name, for our case it is remove-6month-old-file&lt;/li&gt;
&lt;li&gt;2. Since we created a separate S3 bucket to store the audit logs, select apply to all objects in the bucket and Acknowledge the rule.&lt;/li&gt;
&lt;li&gt;3. Life cycle rule actions, select Permanently delete noncurrent versions of objects and Delete expired object delete markers or incomplete multipart uploads&lt;/li&gt;
&lt;li&gt;4. Under Permanently delete noncurrent version, give the value as 180 days.&lt;/li&gt;
&lt;li&gt;5. Under Delete expired object delete markers or incomplete multipart uploads, checked both the options and put 180 days for the files which are not downloaded completely. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--by17KsHx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/upwa8i9ab4snwctfzuw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--by17KsHx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/upwa8i9ab4snwctfzuw9.png" alt="Image description" width="602" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gw5FdcOV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ka7jmc21ybpnsd7dmszr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gw5FdcOV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ka7jmc21ybpnsd7dmszr.png" alt="Image description" width="602" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The final step is to terminate your Redshift cluster after your POC . To delete the cluster, select cluster and under action, select delete.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Op6KZUlu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pgjh5bbqbbhzp4vt4h9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Op6KZUlu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pgjh5bbqbbhzp4vt4h9.png" alt="Image description" width="602" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;&lt;br&gt;
If you do not want to take snapshot, unchecked the create final snap shot option and put the details on the confirmation and click on the delete cluster. It will delete your cluster. Once the cluster is deleted, you can not see the cluster in the cluster list of redshift console.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference Material:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing.html"&gt;https://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing.html&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>awscommunity</category>
      <category>aws</category>
      <category>dataengineering</category>
      <category>awscommunitybuilder</category>
    </item>
    <item>
      <title>Blog -1: Data Engineering - AWS Data and Analytics – Collection – Kinesis Data Stream</title>
      <dc:creator>Sanjeeb Mohapatra</dc:creator>
      <pubDate>Wed, 18 Jan 2023 23:47:22 +0000</pubDate>
      <link>https://dev.to/sanjeeb2017/data-engineering-aws-data-and-analytics-collection-kinesis-data-stream-2mho</link>
      <guid>https://dev.to/sanjeeb2017/data-engineering-aws-data-and-analytics-collection-kinesis-data-stream-2mho</guid>
      <description>&lt;p&gt;Amazon Kinesis data stream is used for collect and process large data stream in real time. Kinesis data stream reads the data from a stream as data records (referred as Producer) and downstream applications using different mechanism (called consumer) to consume the data stream. Kinesis data streams is one of the scalable and durable real-time data streaming service.&lt;/p&gt;

&lt;p&gt;High level Architecture ( The below diagram is from AWS site – Refer - &lt;a href="https://docs.aws.amazon.com/streams/latest/dev/key-concepts.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/streams/latest/dev/key-concepts.html&lt;/a&gt;) &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvhx7rlv08yia0qse4bv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvhx7rlv08yia0qse4bv.png" alt="Image description" width="800" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notes:&lt;/strong&gt; (Below points are some important concepts in Kinesis data stream taken from above AWS site).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The producer continuously produced (pushed) the data to the Kinesis data stream. The data is stored in Shard in Kinesis data stream.&lt;/li&gt;
&lt;li&gt;The Consumers (such as a custom application running on Amazon EC2 or an Amazon Kinesis Data Firehose delivery stream) can store their results using an AWS service such as Amazon DynamoDB, Amazon Redshift, or Amazon S3.&lt;/li&gt;
&lt;li&gt;A Kinesis data stream is a set of shards. Each shard has a sequence of data records. Each data record has a sequence number that is assigned by Kinesis Data Streams. A data record is a unit of data stored in the Shard. The data record contains the sequence number and partition key and data (in blob) and is immutable (cannot be changed).&lt;/li&gt;
&lt;li&gt;The default retention period of data records is 24 hours but it can be extended to 7 days (168 hours)&lt;/li&gt;
&lt;li&gt;A shard is a uniquely identified sequence of data records in a stream. A stream is composed of one or more shards, each of which provides a fixed unit of capacity. Each shard can support up to 5 transactions per second for reads, up to a maximum total data read rate of 2 MB per second and up to 1,000 records per second for writes, up to a maximum total data write rate of 1 MB per second (including partition keys). The data capacity of your stream is a function of the number of shards that you specify for the stream. The total capacity of the stream is the sum of the capacities of its shards.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main objective of this blog is to perform the below use case.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Statement:&lt;/strong&gt; Build a real time streaming application using Amazon Kinesis Data Stream.&lt;/p&gt;

&lt;p&gt;Details: In this lab, we are going to perform the below steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creating a real time data streaming system using Amazon Kinesis Data Streams (KDS).&lt;/li&gt;
&lt;li&gt;We are going to use Amazon Kinesis, AWS Lambda, Amazon S3, IAM &lt;/li&gt;
&lt;li&gt;User will upload a file in S3 (for demo, we will upload via aws management console).&lt;/li&gt;
&lt;li&gt;We set up the event trigger on S3 which will trigger a lambda function. The lambda function will work as a producer and produce the details to Kinesis Data Stream.&lt;/li&gt;
&lt;li&gt;We will use again 2 consumers (lambda) which will read the data from Kinesis data stream. Then any downstream application can be integrated with these consumers. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The high level architecture diagram is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fytpz0ebhlyc9boi027xq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fytpz0ebhlyc9boi027xq.png" alt="Image description" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s jump into the lab&lt;br&gt;
Step -1:  Create a Kinesis Data Stream&lt;/p&gt;

&lt;p&gt;1.To create a Kinesis data stream, login to AWS management console, search Kinesis service.&lt;br&gt;
2.Select Kinesis Data Stream and Click on Create data stream&lt;br&gt;
3.Give the name of the data stream&lt;br&gt;
4.Data Stream Capacity (Here we are selecting provisioned but you can select on demand and depend upon the workload, select required option). We selected the number of shards as 1. However, require number shards can be calculated with input data record length, number of records per second and number of consumer.&lt;br&gt;
5.Finally click on the Click Stream&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvdj264fptxhxmqull9kt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvdj264fptxhxmqull9kt.png" alt="Image description" width="800" height="546"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F67rfgjrymvj964r5sil9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F67rfgjrymvj964r5sil9.png" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step -2: Once the KDS (Kinesis Data Stream) is created, click the stream, go to configuration tab, go to Encryption option, click edit and check enable server-side encryption and use the default encryption type (In this case we used the AWS Managed CMK). Click on the Save changes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2awtkrtguon6wo8mpzaj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2awtkrtguon6wo8mpzaj.png" alt="Image description" width="800" height="562"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step -3: Create S3 bucket &lt;br&gt;
1.Search S3 service from the aws management console search option.&lt;br&gt;
2.Click on create S3 bucket option&lt;br&gt;
3.Give the bucket name, select the right region (select the same region where you have created your Kinesis Stream)&lt;br&gt;
4.Enable the bucket versioning (However it depends upon the requirement)&lt;br&gt;
5.Select the default encryption option (Amazon S3 managed SSE-S3) and click create bucket to create the S3 bucket.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbb79ekndke8mufsgkda5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbb79ekndke8mufsgkda5.png" alt="Image description" width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step -4: Create lambda function (Producer and Consumers)&lt;br&gt;
In this step, we will create 3 lambda functions (One producer, 2 consumers)&lt;br&gt;
Before creating the lambda function, create a role in IAM and role should have access to S3, Kinesis and lambda basic execution rule. We are not providing the details how to create the role, the policy details Json is available below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9r0vub4elg73dlh3er1c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9r0vub4elg73dlh3er1c.png" alt="Image description" width="592" height="697"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step -4: To create the first lambda function (Producer)&lt;br&gt;
1.Search lambda service from AWS management console&lt;br&gt;
2.Click on Create function&lt;br&gt;
3.Select Author from Scratch&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu95r8gton75720vpvfwh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu95r8gton75720vpvfwh.png" alt="Image description" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1.Give the basic information of the lambda function, like name of the function, Runtime environment (In this case we selected python as run time environment)&lt;br&gt;
2.In the permission select the existing role and attach the role ( which you have created in the above step)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhg82rx68lln4fa07tm9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhg82rx68lln4fa07tm9k.png" alt="Image description" width="800" height="570"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the lambda code, copy paste the below code (this is a simple python code, which will read the object from S3 from event trigger and then push to Kinesis data stream). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3z2i1v0jgo53bv0o210.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3z2i1v0jgo53bv0o210.png" alt="Image description" width="800" height="418"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import json
import boto3

def lambda_handler(event, context):
    bucket = event['Records'][0]['s3']['bucket']['name']
    print("Bucket Name: ", bucket)
    file_key_name = event['Records'][0]['s3']['object']['key']
    s3_full_path = bucket+"/"+file_key_name
    print(s3_full_path)
    client = boto3.client('s3')
    data_obj = client.get_object(Bucket=bucket, Key=file_key_name)
    body = data_obj['Body']
    data_string = body.read().decode('utf-8')
    print(data_string)

    K_client = boto3.client('kinesis')
    response = K_client.put_record(
    StreamName='sanjeeb-test-kinesis-stream',
    Data=data_string,
    PartitionKey='123'
     )
    print(response)
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

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

&lt;/div&gt;



&lt;p&gt;Note - We have to not configured the S3 Event trigger yet, to do the same&lt;br&gt;
1.Go to S3 bucket, click on the bucket you have created earlier.&lt;br&gt;
2.Click on Properties&lt;br&gt;
3.Click on create event notification, give the name, put the suffix (in this case we put as .txt so that in case we upload any text file with .txt extension, it will trigger the target event which is a lambda function&lt;br&gt;
4.Select the event type all object created&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmq9yumt1f0yhhodmrexo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmq9yumt1f0yhhodmrexo.png" alt="Image description" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the destination as lambda function and select your lambda function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fael7txnnkqcok9epz2yo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fael7txnnkqcok9epz2yo.png" alt="Image description" width="800" height="471"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step -5: Create consumers ( 2 lambda functions, name will just different but code and other steps will be same).&lt;br&gt;
1.To create a consumer lambda function.&lt;br&gt;
2.Search lambda in aws management console&lt;br&gt;
3.Select lambda, create a function&lt;br&gt;
4.Select author from scratch &lt;br&gt;
5.Give basic information&lt;br&gt;
6.Select the run time environment as python. &lt;br&gt;
7.Under permission, attach the same lambda role which is created in case of producer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frombh2qbsm8jde3zrw9y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frombh2qbsm8jde3zrw9y.png" alt="Image description" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the code section of the lambda, paste the below python code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8i6w0bkabsan8hhre72c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8i6w0bkabsan8hhre72c.png" alt="Image description" width="800" height="412"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import json
import base64

def lambda_handler(event, context):
    record = event['Records']
    for rec in record:
        data_record=rec['kinesis']['data']
        data = base64.b64decode(data_record)
        print(data)
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

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

&lt;/div&gt;



&lt;p&gt;1.To consume the data from Kinesis, we need to add trigger, to do the same, click configuration tab of the lambda.&lt;br&gt;
2.Click on trigger&lt;br&gt;
3.Click on add trigger&lt;br&gt;
4.Select the source kinesis&lt;br&gt;
5.Select activate trigger and make others default&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxarwbccr6udk6xa5xwsu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxarwbccr6udk6xa5xwsu.png" alt="Image description" width="800" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To test e2e, upload a file in the S3 bucket and see the cloud watch logs (log group). Select the consumer log group to see the consumer log and producer log group to see the producer log.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; – We are NOT creating the second lambda consumer function. You can follow the same step and script to create the same ( Only function name needs to be changed).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpwxqv3cjy58m3p6fgso5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpwxqv3cjy58m3p6fgso5.png" alt="Image description" width="800" height="464"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
