<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Taufiq Ibrahim on Medium]]></title>
        <description><![CDATA[Stories by Taufiq Ibrahim on Medium]]></description>
        <link>https://medium.com/@taufiq-ibrahim?source=rss-6734900d838f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*5VuG6hnc7Jo1FI0CLKplgg.jpeg</url>
            <title>Stories by Taufiq Ibrahim on Medium</title>
            <link>https://medium.com/@taufiq-ibrahim?source=rss-6734900d838f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:24:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@taufiq-ibrahim/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Realtime Change Data Capture To BigQuery — No Kafka, No Dataflow]]></title>
            <link>https://blog.devgenius.io/realtime-change-data-capture-to-bigquery-no-kafka-no-dataflow-fb4a6994441b?source=rss-6734900d838f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb4a6994441b</guid>
            <category><![CDATA[google-cloud]]></category>
            <category><![CDATA[pub-sub]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[bigquery]]></category>
            <dc:creator><![CDATA[Taufiq Ibrahim]]></dc:creator>
            <pubDate>Tue, 02 Aug 2022 16:44:16 GMT</pubDate>
            <atom:updated>2022-08-23T09:47:53.923Z</atom:updated>
            <content:encoded><![CDATA[<h3>Realtime Change Data Capture To BigQuery — No Kafka, No Dataflow</h3><h4>A proof-of-concept running CDC from MySQL to BigQuery in realtime with Debezium and Pub/Sub…</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jFSVHigWciilv4JQ" /><figcaption>Photo by <a href="https://unsplash.com/@casparrubin?utm_source=medium&amp;utm_medium=referral">Caspar Camille Rubin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*pbB5XWZtP-tqvtmo7AEjEg.png" /></figure><blockquote>It’s been a while since I am thinking a proof-of-concept using Debezium to perform change data capture or CDC, from RDBMS and ingest the data into BigQuery, low-latency, without Kafka and Kafka Connect. Last time I tried using <a href="https://debezium.io/documentation/reference/stable/operations/debezium-server.html">Debezium Server</a>-Cloud Pub/Sub combo, but hit a disappoinment, because I need to deploy <a href="https://cloud.google.com/dataflow/docs/guides/templates/provided-streaming#pubsub-topic-to-bigquery">Dataflow jobs</a>, which generate additional cost and more resource to manage. So, I dumped the idea at that time. Until…</blockquote><blockquote><strong>Update 2022–08–23</strong> The <a href="https://www.googlecloudcommunity.com/gc/Data-Analytics/BigQuery-Subscription-Error-Incompatible-schema-type-DOUBLE-vs/m-p/458537#M616">issue on using FLOAT or DOUBLE PRECISION data types has been solved</a>. Thanks Google Cloud team!</blockquote><p>Recently, Google Cloud launched <a href="https://cloud.google.com/blog/products/data-analytics/pub-sub-launches-direct-path-to-bigquery-for-streaming-analytics"><strong>new feature to stream data from Pub/Sub directly to BigQuery</strong></a>. With this new <strong>BigQuery Subscription</strong> feature, I might have another alternative solution. I am quite interested to give it a try.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J9HEEUc51nKKEJGn.jpg" /></figure><blockquote><strong>Note: This is just for fun and not intended for production use-cases. I’ll put more detail considerations at the end of this post.</strong></blockquote><h3>Preparing Database And Debezium Server Locally</h3><p>I am using MySQL for the source database and Debezium Server deployed on my laptop using Docker. You can find the docker-compose.yml file below as reference.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/312b84932167bf4bb042896f340e0b14/href">https://medium.com/media/312b84932167bf4bb042896f340e0b14/href</a></iframe><p>Let’s do a little walkthrough about above Docker Compose file:</p><ul><li>MySQL container is preloaded with a database called inventory. We will use a table called inventory.products as test table for this trial.</li><li>Debezium Server container has 2 mount volumes. The first one is the service account file (demo-sa.json) with write access to Pub/Sub and BigQuery. The second one, we mount conf/ directory which contains Debezium Server configuration file called application.properties. You can see the initial configuration file below. Please refer the details on <a href="https://debezium.io/documentation/reference/stable/operations/debezium-server.html#_sink_configuration">Debezium Server sink configuration documentation</a>.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/020b5515ea7f1b8c5aa430cff284b6a9/href">https://medium.com/media/020b5515ea7f1b8c5aa430cff284b6a9/href</a></iframe><p>This is my directory structure.</p><pre>├── conf<br>│   └── application.properties<br>├── demo-sa.json<br>└── docker-compose.yml</pre><p>At this point, we are not yet ready to run the MySQL and Debezium containers, because we need to have these resources available on Google Cloud:</p><ul><li>Pub/Sub schema(s) — optional</li><li>Pub/Sub topic(s)</li><li>Pub/Sub subscription(s)</li><li>BigQuery table(s)</li></ul><p>We will create those resources later.</p><h3>Understand BigQuery Subscription</h3><h4>Pub/Sub Service Account Permission</h4><p>To create a BigQuery subscription, the Pub/Sub service account must have permission to write to the specific BigQuery table and to read the table metadata. Grant the BigQuery Data Editor (<strong>roles/bigquery.dataEditor</strong>) role and the BigQuery Metadata Viewer (<strong>roles/bigquery.metadataViewer</strong>) role to the Pub/Sub service account. Here’s how to do it:</p><ul><li>In the console, go to the IAM page.</li><li>Go to IAM</li><li>Select Include Google-provided role grants.</li><li>Filter by Name: Pub/Sub Service Account. The service account in the format <a href="/service/mailto:service-project-number@gcp-sa-pubsub.iam.gserviceaccount.com">service-project-number@gcp-sa-pubsub.iam.gserviceaccount.com</a></li><li>Click Edit for the Pub/Sub Service Account.</li><li>In the Edit Permissions pane, click Add another role.</li><li>In the Select a role drop-down, enter BigQuery, and select the BigQuery Data Editor role.</li><li>Click Add another role again.</li><li>In the Select a role drop-down, enter BigQuery, and select the BigQuery Metadata Viewer role.</li></ul><p>For more information, see <a href="https://cloud.google.com/pubsub/docs/create-subscription#assign_service_account">Assign BigQuery roles to the Pub/Sub service account</a>.</p><h4>Properties of a BigQuery subscription: Topic Schema</h4><p>BigQuery subscription has an option called <strong>Use topic schema</strong>. This option lets Pub/Sub writes the fields in the topic messages into the corresponding columns in BigQuery table. This sounds interesting. However, it comes with additional requirements:</p><ul><li>The fields in the topic schema and the BigQuery schema must have the same names and their types must be compatible with each other.</li><li>Any optional field in the topic schema must also be optional in the BigQuery schema.</li><li>Required fields in the topic schema do not need to be required in the BigQuery schema.</li><li>If there are BigQuery fields that are not present in the topic schema, these BigQuery fields must be in mode NULLABLE.</li><li>If the topic schema has additional fields that are not present in the BigQuery schema and these fields can be dropped, select the option <strong>Drop unknown fields</strong>.</li></ul><p>If we don’t use Use topic schema option, the subscription writes to a column called data . So, it’s easier to use this option. Just make sure the destination table have the data column.</p><p>More on that in <a href="https://cloud.google.com/pubsub/docs/bigquery#properties_of_a_subscription">Properties of a BigQuery subscription documentation</a>.</p><p>I’ll start with the second option.</p><p>But, before that let’s set some environment variables to make our life easier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8475120acb6822a241c7d17ff9b97813/href">https://medium.com/media/8475120acb6822a241c7d17ff9b97813/href</a></iframe><p>So, without further ado…</p><h3>MySQL CDC Into BigQuery Without Schema Definition</h3><p>Let’s prepare the required resources before we run the CDC part.</p><p>First, create a BigQuery table. Since we use no schema, we will just create a table with data column.</p><pre>CREATE OR REPLACE TABLE<br>&lt;project_id&gt;.&lt;dataset&gt;.mysql_inventory_products_no_schema (<br>  data STRING<br>);</pre><p>Next, create a Pub/Sub topic called mysql.inventory.products. The reason of this naming is, Debezium Server for MySQL use the convention of serverName.databaseName.tableName as the target topic name.</p><pre>gcloud pubsub topics create mysql.inventory.products</pre><p>Next, create a BigQuery Subscription.</p><pre>gcloud pubsub subscriptions create \<br>  mysql.inventory.products-bq-sub \<br>  --topic mysql.inventory.products \<br>  --bigquery-table=$PROJECT_ID.$BQ_DATASET.mysql_inventory_products_no_schema</pre><p>Now, let’s run the containers.</p><pre>docker-compose up</pre><p>The Debezium Server container might exited and restarted several times while waiting MySQL container to be ready.</p><p>Check BigQuery using SQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ejy554N2QM6VZ4vGjPAZlw.png" /><figcaption>Try 1: It works! But what’s that horrible hard to read rows?</figcaption></figure><p>Impressive! But’s why those long-hairy records?</p><p>Because Debezium Server by default sends the raw CDC format, includes the payload and the schema of the data itself. You can learn more about this on <a href="https://debezium.io/documentation/reference/stable/connectors/mysql.html#mysql-events">Debezium MySQL Data change events documentation page</a>.</p><p>We need to use <a href="https://debezium.io/documentation/reference/stable/transformations/event-flattening.html">Debezium’s Single Message Transform (SMT) called New Record State Extraction</a>. Let’s add these lines into application.properties file.</p><pre>debezium.source.transforms=unwrap<br>debezium.source.transforms.unwrap.type=io.debezium.transforms.ExtractNewRecordState<br>debezium.source.transforms.unwrap.add.fields=op,table,source.ts_ms<br>debezium.source.transforms.unwrap.delete.handling.mode=rewrite</pre><p>Let’s reset all the things and start over.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8530f5e021c41aea1f866e66ecc255ec/href">https://medium.com/media/8530f5e021c41aea1f866e66ecc255ec/href</a></iframe><p>Check again using SQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uY_8V8_K2U_WNQb-cAcufg.png" /></figure><p>Now, that’s better. But what are those schema things? Can we get rid of them?</p><p>Of course we can. Add these lines on application.properties and start over.</p><pre>debezium.source.key.converter.schemas.enable=false<br>debezium.source.value.converter.schemas.enable=false</pre><p>Check again using SQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QQa-qeuqX7Xc0PRzwKvTAw.png" /><figcaption>Well that’s great!</figcaption></figure><p>There you go!</p><p>Note that we have additional fields __op, __table, __source_ts_ms and __deleted. It’s because we have these additional configuration on application.properties .</p><pre>debezium.source.transforms.unwrap.add.fields=op,table,source.ts_ms</pre><h3>MySQL CDC Into BigQuery With Schema Definition</h3><p>We have successfully stream MySQL CDC without schema definition into a single-column BigQuery table. Now, let’s try using schema so that we have a tabular data having separated fields matches MySQL source table schema.</p><p>First, let’s clean up all the mess we created earlier.</p><pre># Delete subscription<br>gcloud pubsub subscriptions delete mysql.inventory.products-bq-sub</pre><pre># Delete topic<br>gcloud pubsub topics delete mysql.inventory.products</pre><pre># Drop BigQuery table (Using SQL UI)<br>DROP TABLE &lt;project_id&gt;.&lt;dataset&gt;.mysql_inventory_products_no_schema;</pre><p>Create a new BigQuery table.</p><pre>CREATE OR REPLACE TABLE tibrahim_debezium.mysql_inventory_products (<br>  id INT64 NOT NULL,<br>  name STRING,<br>  description STRING,<br>  weight float64,<br>  __op STRING,<br>  __table STRING,<br>  __source_ts_ms INT64,<br>  __deleted STRING<br>);</pre><p>Next, let’s create schema for Pub/Sub topic. This schema must be a valid AVRO schema which match the source table definition.</p><pre>gcloud pubsub schemas create mysql.inventory.products-schema \<br>--type=AVRO \<br>--definition=&#39;{&quot;type&quot;:&quot;record&quot;,&quot;name&quot;:&quot;MysqlInventoryProductsSchema&quot;,&quot;fields&quot;:[{&quot;type&quot;:&quot;int&quot;,&quot;optional&quot;:false,&quot;name&quot;:&quot;id&quot;},{&quot;type&quot;:&quot;string&quot;,&quot;optional&quot;:false,&quot;name&quot;:&quot;name&quot;},{&quot;type&quot;:&quot;string&quot;,&quot;optional&quot;:false,&quot;name&quot;:&quot;description&quot;},{&quot;type&quot;:&quot;float&quot;,&quot;optional&quot;:false,&quot;name&quot;:&quot;weight&quot;},{&quot;type&quot;:&quot;string&quot;,&quot;optional&quot;:true,&quot;name&quot;:&quot;__op&quot;},{&quot;type&quot;:&quot;string&quot;,&quot;optional&quot;:true,&quot;name&quot;:&quot;__table&quot;},{&quot;type&quot;:&quot;long&quot;,&quot;optional&quot;:true,&quot;name&quot;:&quot;__source_ts_ms&quot;},{&quot;type&quot;:&quot;string&quot;,&quot;optional&quot;:true,&quot;name&quot;:&quot;__deleted&quot;}]}&#39;</pre><p>Now, let’s create Pub/Sub topic using the schema.</p><pre>gcloud pubsub topics create mysql.inventory.products --message-encoding=json --schema=mysql.inventory.products-schema</pre><p>Now, the new feature, BigQuery Subscription…with schema</p><pre>gcloud pubsub subscriptions create mysql.inventory.products-bq-sub \<br> --topic mysql.inventory.products \<br> --bigquery-table=$PROJECT_ID.$BQ_DATASET.mysql_inventory_products \<br> --use-topic-schema</pre><p>Ouch, we got an error here.</p><pre>ERROR: Failed to create subscription [projects/&lt;PROJECT_ID&gt;/subscriptions/mysql.inventory.products-bq-sub]: Incompatible schema type for field weight: DOUBLE vs. FLOAT.<br>ERROR: (gcloud.pubsub.subscriptions.create) Failed to create the following: [mysql.inventory.products-bq-sub].</pre><p>It seems that BigQuery Subscription is having an issue/bug related to float data type. I wrote a <a href="https://www.googlecloudcommunity.com/gc/Data-Analytics/BigQuery-Subscription-Error-Incompatible-schema-type-DOUBLE-vs/m-p/449166">post on Google Cloud Community Forum about this issue</a>, and it seems that I am not the only one experience this error.</p><p>Okay, I am a bit disappointed about this issue. But, let’s not stop here. We’ll try using another table without float column. Let’ use addresses table.</p><p>Changed Debezium Server application.properties:</p><pre>debezium.source.table.include.list=inventory.addresses</pre><p>Let’s create a new BigQuery table for addresses table.</p><pre>CREATE OR REPLACE TABLE &lt;project_id&gt;.&lt;dataset&gt;.mysql_inventory_addresses (<br>  `id` int64 NOT NULL,<br>  `customer_id` int NOT NULL,<br>  `street` STRING NOT NULL,<br>  `city` STRING NOT NULL,<br>  `state` STRING NOT NULL,<br>  `zip` STRING NOT NULL,<br>  `type` STRING NOT NULL,<br>  __op STRING,<br>  __table STRING,<br>  __source_ts_ms INT64,<br>  __deleted STRING<br>);</pre><p>Next, create Pub/Sub schema, topic, BigQuery Subscription and run Debezium Server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f74fe27341003938bc088bc2c01fbea8/href">https://medium.com/media/f74fe27341003938bc088bc2c01fbea8/href</a></iframe><p>There you go, my friend, a beautiful tabular view of our data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LQcJ6Yd1kqLgVRmnLUviPg.png" /></figure><h3>My Takeaways</h3><p>Running change data capture without Kafka and Kafka Connect is possible with the help of Debezium Server and Pub/Sub. With the release of BigQuery Subscription feature, it is even easier to stream directly, without Cloud Dataflow, into BigQuery table. Less resource to monitor, less hassle and less cost.</p><p>However, this simpler approach comes with another issues:</p><ul><li><strong>Schema evolution</strong><br>Currently, after a schema is associated with a topic, you cannot update the schema. If your source table schema changed, then the CDC stream will fail. <a href="https://docs.confluent.io/platform/current/schema-registry/index.html">Confluent Schema Registry</a> or <a href="https://www.apicur.io/registry/">Apicurio Schema Registry</a> already solved this challenge. There’s a <a href="https://issuetracker.google.com/issues/206147008">Google Issue Tracker</a> about this. Let’s hope Google Pub/Sub team will solve this in near future. If your data source have a frequent schema changes, perhaps you’d be better stick to Kafka stack.</li><li><strong>Topic and Destination Table Auto-Creation/Schema Auto-Evolution</strong><br>As of the time of writing this article, we need to create schema, topic, subscription and BigQuery table before running Debezium. If you have tens or hundreds of tables, then you need to come up with some automation on creating, managing and destroying the resources. More mature framework like <a href="https://docs.confluent.io/platform/current/connect/overview.html">Kafka Connect</a> and the open source <a href="https://github.com/confluentinc/kafka-connect-bigquery">Kafka Connect BigQuery Sink</a> already solve this issue. Again, if you have problem with this issue, then perhaps you should stick with Kafka Connect or other mature framework.</li></ul><p>If you don’t have any of above issues, then this approach might work for you. Anyway, this feature is really great. Not only for change data capture purpose, you might use it for a lot of things such as sending IoT sensor data directly to your BigQuery. Or capturing web events. The sky is the limit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb4a6994441b" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/realtime-change-data-capture-to-bigquery-no-kafka-no-dataflow-fb4a6994441b">Realtime Change Data Capture To BigQuery — No Kafka, No Dataflow</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless Kafka Streaming Application Using AWS MSK + AWS Lambda + Serverless Framework]]></title>
            <link>https://towardsaws.com/serverless-kafka-streaming-application-using-aws-msk-aws-lambda-serverless-framework-ff8f44da8ba4?source=rss-6734900d838f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff8f44da8ba4</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Taufiq Ibrahim]]></dc:creator>
            <pubDate>Tue, 04 May 2021 12:35:37 GMT</pubDate>
            <atom:updated>2021-05-31T02:17:25.583Z</atom:updated>
            <content:encoded><![CDATA[<p>Amazon Managed Streaming for Apache Kafka (<a href="https://aws.amazon.com/msk/">Amazon MSK</a>) is a fully managed, highly available service that uses <a href="https://kafka.apache.org/">Apache Kafka</a> to process real-time streaming data.</p><p>In August 2020, AWS <a href="https://aws.amazon.com/about-aws/whats-new/2020/08/aws-lambda-now-supports-amazon-managed-streaming-for-apache-kafka-as-an-event-source/">launched support for Amazon Managed Streaming Kafka as an event source for Amazon Lambda</a>.</p><p>As a cloud giant, this service will attract more Kafka users to use more of Amazon services.</p><p>I wrote this as I tried to explore the possibility to migrate my still-on-development Python code running on a Docker container inside an EC2 instance, into a serverless app on AWS Lambda.</p><h3>The Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*aillmgtFSmmPaNGNISFQ8w.png" /><figcaption>Simple MSK Lambda event processing architecture</figcaption></figure><p>Like any other approach, this approach has several pros and cons.</p><h4>Pros</h4><ul><li>Easy development and deployment</li><li>Suitable for quick event-based architecture deployment with low-to-medium traffic</li><li>Battle proved by AWS Lambda</li><li>No resource to manage. You can focus totally on the logic</li><li>Pay as you use cost, depends on Lambda invocation cost</li><li>Logging by AWS Cloudwatch</li><li>Serverless Framework popularity and many supporting plugins</li><li>It’s just simple Python code!</li></ul><h4>Cons</h4><ul><li>Hard (if not impossible) to test locally, since AWS MSK deployed on secured VPC</li><li>Only two consumer group message available, since the beginning of the topic (TRIM_HORIZON) and LATEST</li><li>Not suitable for high traffic topic</li><li>Sometimes deployment and removal takes a quite a long time</li></ul><p>For a quick POC or simple message processing, this framework is a no-brainer and dirt cheap!</p><h3>Using Serverless Framework For Kafka Event Processing</h3><p>The source code for this article is available on <a href="https://github.com/taufiqibrahim/serverless-stream-processing-aws-msk-lambda">Github</a>. We will use <a href="https://github.com/taufiqibrahim/serverless-stream-processing-aws-msk-lambda/tree/main/apps/demo-walkthrough">apps/demo-walkthrough</a> code for the rest of the article.</p><p>One of the main components of this framework is <a href="http://serverless.com/">Serverless Framework</a>. The reason why we choose this was:</p><ul><li>Our familiarity with Serverless</li><li>Easy to deploy and teach</li></ul><p>Let us go through the demo as described <a href="https://github.com/taufiqibrahim/serverless-stream-processing-aws-msk-lambda/blob/main/apps/demo-walkthrough/walkthrough.md">here</a>.</p><h4>Step 1: Define System Design</h4><p>Here’s the plan. Basically, the implementation were something like this:</p><ul><li>Subscribe to a topic from MSK. New record in Incoming Topic will trigger AWS Lambda function</li><li>Lambda function will perform simple enrichment lookup using MySQL database</li><li>Produce enriched data into output topic in MSK</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*00_X4Krx23jKlE5UCp9v1Q.png" /></figure><h4>Step 2: AWS Infrastructure Requirements</h4><ul><li>AWS VPC</li><li>Running AWS MSK cluster inside VPC</li><li>S3 deployment bucket which is stored in AWS_S3_DEPLOYMENT_BUCKET</li><li>Lambda execution role</li><li>Lambda security group</li><li>MySQL RDS</li></ul><p>This document does not specify how to create AWS VPC and MSK clusters. You can find the details on <a href="https://docs.aws.amazon.com/msk/latest/developerguide/getting-started.html">https://docs.aws.amazon.com/msk/latest/developerguide/getting-started.html</a>.</p><p>More detail regarding using AWS MSK with Lambda here <a href="https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html">https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html</a></p><h4>2.1 Create Lambda Execution Role</h4><ul><li>Go to AWS IAM &gt; Roles</li><li>Create role</li><li>Choose a use case = Lambda</li><li>Next: Permissions</li><li>Attach permissions policies. In the search box, enter the policy name AWSLambdaMSKExecutionRole</li><li>Create a new role with the name AWSLambdaMSKDemoWalkthroughRole</li></ul><h4>2.2 Create Lambda Security Group</h4><p>We also need to create a Security Group with inbound access to AWS MSK.</p><ul><li>Go to AWS EC2 &gt; Security Groups</li><li>Create Security Group</li><li>Security group name: AWSLambdaMSKDemoWalkthroughSG</li><li>Description: AWSLambdaMSKDemoWalkthroughSG</li><li>VPC: same VPC ID with your MSK cluster</li><li>Inbound rules: Custom TCP 9092 with Source = Anywhere</li></ul><h4>2.3 Allow Inbound On MSK from Lambda Security Group</h4><p>Now, we need to allow inbound from Lambda Security Group on MSK.</p><ul><li>Go to MSK</li><li>Find Security groups applied</li></ul><p>Add inbound rules:</p><ul><li>Self-referencing inbound rule from MSK own Security groups applied</li><li>from Lambda Security Group AWSLambdaMSKDemoWalkthroughSG on port 9092</li></ul><h4>2.4 Populate MySQL RDS Database</h4><p>We will use the MySQL database as a lookup source. So we need to populate it first using SQL available on <a href="https://github.com/taufiqibrahim/serverless-stream-processing-aws-msk-lambda/blob/main/apps/demo-walkthrough/data/mysql.sql">apps/demo-walkthrough/data/mysql.sql</a>. It will create and populate a table called demo.customers.</p><h3>Step 3: How To Initialize Stream Processing demo-walkthrough App</h3><p>This is how we initialize apps/demo-walkthrough. Skip step 3 if you want to try demo-walkthrough . You can use these steps to initiate a new app directory, though.</p><p>First, we install Serverless Framework globally.</p><pre>npm install -g serverless</pre><p>Next, we install local dependencies as declared in package.json. Serverless Plugins should be declared here as well.</p><pre>npm install</pre><p>In this walkthrough, we want to create a new stream processing application called demo-walkthrough. The code lives inside apps/demo-walkthrough/ a directory which does currently not exist yet. We will create it using the Serverless framework command line.</p><pre># Go inside apps/ directory<br>cd apps/</pre><pre># Create app skeleton using serverless create<br>serverless create --template aws-python3 --name demo-walkthrough --path demo-walkthrough</pre><p>Now our repository structure becomes like this:</p><pre>.<br>├── apps<br>│   └── demo-walkthrough<br>│       ├── handler.py<br>│       └── serverless.yml</pre><h4>serverless.yml</h4><p><em>todo about what I changed.</em></p><h4>env.&lt;STAGE&gt;.json</h4><p>This is called Serverless Variables, which will be used to render serverless.yml . Below is the example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e51e699d8913d6c7e7cffb3a859627ad/href">https://medium.com/media/e51e699d8913d6c7e7cffb3a859627ad/href</a></iframe><h4>requirements.txt</h4><p>As a common thing in Python, we also prepare a requirements.txt file to list all required Python libraries needed by this app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/adb401cb76fe2b5d36f609b47b8e049f/href">https://medium.com/media/adb401cb76fe2b5d36f609b47b8e049f/href</a></iframe><p>Install the serverless plugin, here I used --stage staging since it was required by my serverless.yml</p><pre>serverless plugin install -n serverless-python-requirements --stage staging</pre><h3>4 How To Develop Functions</h3><p>This part is where we start to develop Python code used for event processing.</p><h4>4.1 Prepare Python Virtual Environment</h4><p>Let’s start by creating a new Python virtual environment inside apps/demo-walkthrough/ the directory. We will develop and perform deployment in an active virtual environment.</p><pre># Go into app directory<br>cd apps/demo-walkthrough/</pre><pre># Create virtualenv if not exists<br>virtualenv venv --python=python3.8</pre><pre># Activate<br>. venv/bin/activate</pre><p>Install dependencies using requirements.txt.</p><pre>pip install -r requirements.txt</pre><h4>4.2 Example p01OrdersEnrichCustomerLocation Function</h4><p>This function do:</p><ul><li>Takes event records from topic demo-walkthrough-orders as input</li><li>Perform customer address lookup from MySQL database table demo.customers</li><li>Produce Kafka topic called demo-walkthrough-p01OrdersEnrichCustomerLocation with some additional enrichment fields</li></ul><p>The demo code written in <a href="https://github.com/taufiqibrahim/serverless-stream-processing-aws-msk-lambda/blob/main/apps/demo-walkthrough/p01OrdersEnrichCustomerLocation.py">apps/demo-walkthrough/p01OrdersEnrichCustomerLocation.py</a>.</p><p>Some helper functions were used and available under utils/ directory. You can add more functions here, as it&#39;s included on apps/demo-walkthrough/serverless.yml config file.</p><h3>5 Deploy Functions</h3><p>On last step before deployment. We need to create a Serverless Variables stored on a JSON file. Copy apps/demo-walkthrough/env.example.json and stored it as file called apps/demo-walkthrough/env.dev.json. This file will be ignored by .gitignore since it will contain credentials.</p><p>Below is the explanation for each key value pairs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/048538489afed262fcc6208ee611152b/href">https://medium.com/media/048538489afed262fcc6208ee611152b/href</a></iframe><p>Before continue to the next step, please make sure you’re Python virtual environment is in active state.</p><p>Now let’s print our serverless.yml config file with all variables resolved.</p><pre>serverless print --stage dev</pre><p>It should print something like this without any warning.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62596bd5113d248970059bab78894ac7/href">https://medium.com/media/62596bd5113d248970059bab78894ac7/href</a></iframe><p>If no warning, then we’re good to go. Let’s deploy it.</p><pre>serverless deploy --stage dev</pre><p>You will see in Lambda console there is a new Application called demo-walkthrough .</p><p>Let’s produce our simple JSON data to topic called demo-walkthrough-orders inside AWS MSK cluster. We will use a versatile tool called kafkacat <a href="https://github.com/edenhill/kafkacat">https://github.com/edenhill/kafkacat</a>. Since AWS MSK cluster deployed inside a private VPC, we must invoke the command on a bastion host or accessible EC2 which can access MSK.</p><pre>kafkacat -P -b &lt;AWS_MSK_BOOTSTRAP_SERVERS_URLS&gt; -t demo-walkthrough-orders -l ./data/orders.txt</pre><p>We will use orders.txt to simulate incoming events.</p><p>Now, let’s check the topics</p><p><strong>Source topic</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4182eb75d484e782148fe39fb88db811/href">https://medium.com/media/4182eb75d484e782148fe39fb88db811/href</a></iframe><h4>Output topic</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d83e108f09aa50c6cd84e234327feda/href">https://medium.com/media/9d83e108f09aa50c6cd84e234327feda/href</a></iframe><p>To remove Serverless stack, simply run this command.</p><pre>serverless remove --stage dev</pre><p>It will remove all resources created by Serverless Framework.</p><h3>Closing Thoughts</h3><p>So, now we already have a simple event processing application using AWS MSK and AWS Lambda which is orchestrated using Serverless Framework.</p><p>Some tricks when using this approach:</p><ul><li>Make sure a single function only perform single task. For example: transforming data structure only or making a single database call only.</li><li>Lambda has a limit of maximum execution time. But, don’t use it. We don’t want a event processor that process 100 records for a 5 minutes each cycle. Make sure your process will be finished on hundreds of milliseconds. Make them simple enough.</li><li>For function with database call, make sure you invoke a single batch query. Use tuple filtering such as <br>WHERE (field1, field2) IN ((&#39;x1&#39;, &#39;y1&#39;), (&#39;x2&#39;, &#39;y2&#39;), ...) . SQLAlchemy utilities can be found within<a href="https://github.com/taufiqibrahim/serverless-stream-processing-aws-msk-lambda/blob/main/utils/db.py">db.py</a> in the repo.</li><li>If you have complex and long processing logic, break them into several functions. And think like a DAG. Such as:</li></ul><pre>topic0 &gt;&gt; p01Process1Func &gt;&gt; p01Process1TopicOut<br>p01Process1TopicOut &gt;&gt; p02Process2Func &gt;&gt; p02Process2TopicOut<br>p01Process1TopicOut &gt;&gt; p03Process3Func &gt;&gt; p04Process4TopicOut<br>p02Process2TopicOut &gt;&gt; p05WriteDBFunc</pre><pre># well yes, that&#39;s a DAG!</pre><ul><li>Try to tune batchSize and find the sweet number. This can be different for each process.</li></ul><p>Some notes that are not covered in this article:</p><ul><li>You have to set up monitoring and alerting in case your function stop functioning. In Bizzy, we are using New Relic which is really helpful for monitoring.</li><li>We are planning to set up visualization tool within this simple framework. This is a screenshot of our prototype:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZkUxbsjnVQUoU4nC30O8tg.png" /></figure><ul><li>We are planning to set up metadata integration to <a href="https://datahubproject.io/">Datahub</a>.</li></ul><p>Anyway, thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff8f44da8ba4" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/serverless-kafka-streaming-application-using-aws-msk-aws-lambda-serverless-framework-ff8f44da8ba4">Serverless Kafka Streaming Application Using AWS MSK + AWS Lambda + Serverless Framework</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Pipeline Service Graph Using AWS Neptune Part 1]]></title>
            <link>https://taufiq-ibrahim.medium.com/data-pipeline-service-graph-using-aws-neptune-part-1-6aa312e872cf?source=rss-6734900d838f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6aa312e872cf</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[neptune]]></category>
            <category><![CDATA[service-map]]></category>
            <category><![CDATA[data-pipeline]]></category>
            <dc:creator><![CDATA[Taufiq Ibrahim]]></dc:creator>
            <pubDate>Fri, 12 Mar 2021 18:29:37 GMT</pubDate>
            <atom:updated>2021-03-12T18:29:37.184Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><p><em>todo</em></p><h3>Goals</h3><p><em>todo</em></p><h3>The Journeys</h3><p><em>todo</em></p><h4>1 Creating Solution Architecture</h4><p><em>todo</em></p><h4>2 Deploying AWS Neptune DB</h4><p>We will deploy a Neptune instance on AWS using Cloudformation below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e335ed8886bfa6f85c6482900822db05/href">https://medium.com/media/e335ed8886bfa6f85c6482900822db05/href</a></iframe><p>We also need to have a file called <strong>neptune.params.prod.json</strong>, which define all parameters required by Cloudformation template. Below is one example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfda03048e089bfba7d84364662b0b7a/href">https://medium.com/media/cfda03048e089bfba7d84364662b0b7a/href</a></iframe><p>To deploy the stack, let’s use below command:</p><pre>aws cloudformation create-stack \<br>--stack-name neptune-data-pipeline-graph-prod \<br>--template-body file://neptune-cfn.yaml \<br>--parameters file://neptune.params.prod.json</pre><p>Let us summarize what above Cloudformation YAML and deploy command does.</p><ul><li>The stack will use existing VPC Id, Subnet IDs (at least 2), and SNS Topic (ARN). So please make sure you created one and mention it on neptune.params.prod.json .</li><li>The stack will create below resources:</li></ul><pre>Resource Type                         Resource Logical Id</pre><pre>AWS::CloudWatch::Alarm                NeptunePrimaryCpuAlarm<br>AWS::CloudWatch::Alarm     NeptunePrimaryGremlinRequestsPerSecAlarm<br>AWS::CloudWatch::Alarm                NeptunePrimaryMemoryAlarm<br>AWS::CloudWatch::Alarm     NeptunePrimarySparqlRequestsPerSecAlarm<br>AWS::EC2::SecurityGroup               NeptuneDBSG<br>AWS::IAM::ManagedPolicy               NeptuneCloudWatchPolicy<br>AWS::IAM::ManagedPolicy               NeptuneS3Policy<br>AWS::IAM::Role                        NeptuneRole<br>AWS::Neptune::DBCluster               NeptuneDBCluster<br>AWS::Neptune::DBClusterParameterGroup NeptuneDBClusterParameterGroup<br>AWS::Neptune::DBInstance              NeptuneDBInstance<br>AWS::Neptune::DBParameterGroup        NeptuneDBParameterGroup<br>AWS::Neptune::DBSubnetGroup           NeptuneDBSubnetGroup</pre><p>Neptune database will be there in AWS console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*v35jKIVIP4pyaO-b0_RU-Q.png" /></figure><h4>3 Using Graphexp To Explore Neptune Graph</h4><p>We will use a very cool tools called <a href="https://github.com/bricaud/graphexp">Graphexp</a> to explore and visualize (even do some editing) Neptune database we created earlier.</p><p>Download release ZIP file from <a href="https://github.com/bricaud/graphexp/releases">https://github.com/bricaud/graphexp/releases</a>. For example I will use latest version at the time writing this article which is 0.8.0.</p><pre># Download source code<br>wget <a href="https://github.com/bricaud/graphexp/archive/v0.8.0.zip">https://github.com/bricaud/graphexp/archive/v0.8.0.zip</a></pre><pre># Extract the zip<br>unzip v0.8.0.zip</pre><pre># Enter the directory<br>cd graphexp-0.8.0/</pre><p>Edit file scripts/graphioGremlin.js . Find function called send_to_server , replace http to https and ws to wss .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c36d3b48b217bc0f8dc3d4003559cf8/href">https://medium.com/media/3c36d3b48b217bc0f8dc3d4003559cf8/href</a></iframe><p>Serve using simple Python server:</p><pre>python -m SimpleHTTPServer 5000</pre><p>Graphexp will run locally on <a href="http://localhost:5000/">http://localhost:5000</a>.</p><p>Now, we need to create a tunnel between our local machine to Neptune instance via an EC2 bastion host instance as described <a href="https://aws.amazon.com/premiumsupport/knowledge-center/neptune-gremlin-graph-graphexp/">here</a>.</p><pre>ssh -L 8182:mydbcluster.cluster-123456789012.eu-west-1.neptune.amazonaws.com:8182 -i my_keypair.pem ec2-user@ec2-11-111-11-111.eu-west-1.compute.amazonaws.com</pre><p>Now, test on <a href="http://localhost:5000/">http://localhost:5000</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BT0aWiTEX7h1CNq40SCFKg.png" /></figure><p>We’re ready to do some interesting things on Part 2.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6aa312e872cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Flink: SQL Client Walkthrough]]></title>
            <link>https://taufiq-ibrahim.medium.com/apache-flink-sql-client-walkthrough-da2a9a5ef1ca?source=rss-6734900d838f------2</link>
            <guid isPermaLink="false">https://medium.com/p/da2a9a5ef1ca</guid>
            <dc:creator><![CDATA[Taufiq Ibrahim]]></dc:creator>
            <pubDate>Sat, 16 May 2020 14:21:28 GMT</pubDate>
            <atom:updated>2020-05-16T14:21:28.467Z</atom:updated>
            <content:encoded><![CDATA[<p>This article shall give you walkthrough in using Apache Flink SQL Client based on my experience on learning and deploy Flink streaming applications.</p><h3>The Mission</h3><p>Supposed that we have a Kafka topic called order_billing which has schema like this:</p><pre>TODO JSON SCHEMA</pre><p>And, this is the example of the records using kafkacat utility.</p><pre>TODO SAMPLE RECORDS</pre><p>We want to have an aggregated view on do_no. The fields need to be aggregated are:</p><ul><li>amount → amount_agg</li><li>selling_amount → selling_amount_agg</li><li>discount_amount → discount_amount_agg</li></ul><h3>If order_billing is a RDBMS Table</h3><p>For us who are experienced using RDBMS, this task is very simple and straight forward. All we need to do is just write a very simple query like this.</p><p><a href="https://gist.github.com/taufiqibrahim/06deede709c001d4aed873805a78a881">https://gist.github.com/taufiqibrahim/06deede709c001d4aed873805a78a881</a></p><p><a href="https://gist.github.com/taufiqibrahim/06301842904c42c7a636efa809313079">https://gist.github.com/taufiqibrahim/06301842904c42c7a636efa809313079</a></p><p><a href="https://gist.github.com/taufiqibrahim/06301842904c42c7a636efa809313079">https://gist.github.com/taufiqibrahim/06301842904c42c7a636efa809313079</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da2a9a5ef1ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Kubernetes]]></title>
            <link>https://taufiq-ibrahim.medium.com/getting-started-with-kubernetes-213e3e6afc31?source=rss-6734900d838f------2</link>
            <guid isPermaLink="false">https://medium.com/p/213e3e6afc31</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[flask]]></category>
            <dc:creator><![CDATA[Taufiq Ibrahim]]></dc:creator>
            <pubDate>Tue, 17 Mar 2020 23:05:37 GMT</pubDate>
            <atom:updated>2020-03-18T01:46:00.862Z</atom:updated>
            <content:encoded><![CDATA[<p>So, what is this all about? Another hype? Another trending tech things? Nope, this is just another simple article to show you on how to get started with Kubernetes and understand some simple operations on it. Another reason was, I found it difficult to find written article about end to end Kubernetes deployment.</p><h3>The Equipment: Kubernetes</h3><blockquote>Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.</blockquote><h3>The Stage: Amazon EKS</h3><blockquote>Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed Kubernetes service.</blockquote><h3>The Show</h3><h4>Creating Kubernetes Cluster on Amazon EKS</h4><p>Let’s start by writing simple YAML file and store it as eks.yaml. As simple as this:</p><pre>apiVersion: eksctl.io/v1alpha5<br>kind: ClusterConfig</pre><pre>metadata:<br>  name: my-cluster<br>  region: ap-southeast-1<br>managedNodeGroups:<br>  - name: job-manager<br>    instanceType: t3a.micro<br>    desiredCapacity: 2<br>    minSize: 2<br>    maxSize: 10<br>    tags:<br>      &#39;Project&#39;: &#39;KubernetesNoob&#39;</pre><p>We will use a cool tool called <a href="https://eksctl.io/">eksctl</a>. This is a simple tool for creating Kubernetes cluster on EKS. Make sure you already set up aws configure command before.</p><pre>$ eksctl create cluster -f eks.yaml</pre><p>Above command basically doing these stuffs:</p><ul><li>Create a new cluster using configuration file eks.yaml.</li><li>The cluster will named as my-cluster and will be created on Singapore region.</li><li>It will have 2 t3a.micro EC2 instances and tagged using Project: KubernetesNoob.</li></ul><p>It will take a while to finish, around 10 to 15 minutes. While waiting for the cluster to be ready, let’s create a small Flask application.</p><h4>Creating Simple Flask Webserver</h4><p>Create a new requirements.txt file and populate with this.</p><pre>aniso8601==8.0.0<br>attrs==19.3.0<br>click==7.1.1<br>Flask==1.1.1<br>flask-restplus==0.13.0<br>importlib-metadata==1.5.0<br>itsdangerous==1.1.0<br>Jinja2==2.11.1<br>jsonschema==3.2.0<br>MarkupSafe==1.1.1<br>pkg-resources==0.0.0<br>pyrsistent==0.15.7<br>pytz==2019.3<br>six==1.14.0<br>Werkzeug==0.16.1<br>zipp==3.1.0</pre><p>Create a new Python3.7 virtual environment, activate it and install the dependencies.</p><pre>$ virtualenv venv --python=python3.7<br>$ . venv/bin/activate<br>(venv)$ pip install -r requirements.txt</pre><p>Create a directory called app and populate it with a file called main.py using below contents.</p><pre>import platform<br>from flask import Flask<br>from flask_restplus import Resource, Api</pre><pre>app = Flask(__name__)<br>api = Api(app)</pre><pre><a href="http://twitter.com/api">@api</a>.route(&#39;/uname&#39;)<br>class HostName(Resource):<br>    def get(self):<br>        return {&#39;uname&#39;: platform.uname()}</pre><pre>if __name__ == &#39;__main__&#39;:<br>    app.run(host=&quot;0.0.0.0&quot;, debug=True)</pre><p>Run the webserver using:</p><pre>(venv)$ python app/main.py</pre><p>Check it on <a href="http://localhost:5000/">http://localhost:5000</a> .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*yv3aGEheIGSEB1BtU1mu7A.png" /><figcaption>my-flask service running locally using Python</figcaption></figure><p>Cool, now let’s Dockerized our new app. Create a file called Dockerfile.</p><pre>FROM python:3.7-alpine</pre><pre>RUN mkdir /app<br>WORKDIR /app<br>ADD ./app /app/<br>ADD ./requirements.txt /app/<br>RUN pip install -r requirements.txt</pre><pre>EXPOSE 5000<br>CMD [&quot;python&quot;, &quot;/app/main.py&quot;]</pre><p>That file is a set of instructions Docker will use to build the image. For this simple application, Docker is going to:</p><ol><li>Get the official <a href="https://hub.docker.com/_/python/">Python Base Image</a> for version 3.7 from Docker Hub.</li><li>In the image, create a directory named app.</li><li>Set the working directory to that new app directory.</li><li>Copy the local directory’s contents to that new folder into the image.</li><li>Run the pip installer (just like we did earlier) to pull the requirements into the image.</li><li>Inform Docker the container listens on port 5000.</li><li>Configure the starting command to use when the container starts.</li></ol><p>Now, we must build the container image.</p><pre>$ docker build -f Dockerfile -t my-flask-image:latest .</pre><p>After image building process finished, we need to check wether the image is listed on our local Docker.</p><pre>$ docker images<br>REPOSITORY                                                                         TAG                 IMAGE ID            CREATED             SIZE<br>my-flask-image                                                                     latest              0dc76af1b731        26 seconds ago      123MB</pre><p>Our Docker image is successfully listed and the size is 123MB. Let’s try to run this image locally before moving further.</p><pre>$ docker run -p 5001:5000 my-flask-image</pre><p>Test that on <a href="http://localhost:5001/">http://localhost:5001</a> since we mapped the Docker container port 5000 into host port 5001.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*yv3aGEheIGSEB1BtU1mu7A.png" /><figcaption>my-flask service running locally on Docker</figcaption></figure><p>Now, let’s check our EKS cluster. It should be ready by now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*y6g06lRX-7sSUTmZ0_nJcw.png" /></figure><h4>Upload Docker Image to Amazon ECR</h4><p>Currently our image, my-flask-image, is only available locally. In order to be available for use by our cluster it should be uploaded somewhere on the internet. Since we’re using AWS services, we will use another service called Amazon ECR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*wohbQMkt5idfILcOmABA4g.png" /></figure><p>Create a new repository called my-flask.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*qIRa9bTmVeaQntfe1Gy3Nw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*8n2brYZNrNa2Bfz9FqKRPg.png" /></figure><p>Click on <strong>View push commands</strong> button and follow the guidelines to upload your Docker image.</p><p>Depends on your internet speed, the upload process might take a while.</p><h3>Get into The World of Kubernetes</h3><p>Now, we have reached our new world…Kubernetes. Let’s recap first:</p><ul><li>We have a running Kubernetes cluster on AWS EKS</li><li>We already have our app image in AWS ECR</li></ul><p>For interacting with Kubernetes cluster, we need a tool called kubectl. Please follow the installation guide <a href="https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html">here</a>.</p><p>Let’s we what we can do with this tool. You can find the cheatsheet provided by Kubernetes on <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/">https://kubernetes.io/docs/reference/kubectl/cheatsheet/</a>.</p><p>First, let’s check all the services.</p><pre>$ kubectl get svc<br>NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE<br>kubernetes   ClusterIP   10.100.0.1   &lt;none&gt;        443/TCP   58m</pre><p>Let’s see all available nodes (EC2 instances).</p><pre>$ kubectl get nodes<br>NAME                                                STATUS   ROLES    AGE   VERSION<br>ip-192-168-45-235.ap-southeast-1.compute.internal   Ready    &lt;none&gt;   57m   v1.14.9-eks-1f0ca9<br>ip-192-168-95-3.ap-southeast-1.compute.internal     Ready    &lt;none&gt;   57m   v1.14.9-eks-1f0ca9</pre><p>I know that you’re really excited now and come up with question, “Show us how to deploy the app?”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*9H0kqT3Gu0ceThn2.jpg" /></figure><p>Okay, calm down. Before we can deploy the app into the cluster, we need to create one more YAML file, we will call this file deployment.yaml.</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: my-flask-service<br>spec:<br>  selector:<br>    app: my-flask<br>  ports:<br>  - protocol: &quot;TCP&quot;<br>    port: 6000<br>    targetPort: 5000<br>  type: LoadBalancer</pre><pre>---<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: my-flask<br>spec:<br>  selector:<br>    matchLabels:<br>      app: my-flask<br>  replicas: 2<br>  template:<br>    metadata:<br>      labels:<br>        app: my-flask<br>    spec:<br>      containers:<br>      - name: my-flask<br>        image: &lt;IMAGE_URI_FROM_ECR&gt;<br>        ports:<br>        - containerPort: 5000</pre><p>Above YAML basically give instructions to Kubernetes cluster for what we want:</p><ul><li>A load-balanced service exposing port 6000</li><li>Two instances of the my-flask container running using Docker image hosted on AWS ECR.</li></ul><p>Use kubectl to send the YAML file to Kubernetes by running the following command:</p><pre>$ kubectl apply -f deployment.yaml<br>service/my-flask-service created<br>deployment.apps/my-flask created</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*q2L_YWfaANV5hW3AkbZjJg.png" /></figure><p>Now, the question is “How do I access those running containers?”.</p><p>Enter kubectl proxy. Run this command:</p><pre>$ kubectl proxy --port 8080</pre><p>Your API will be accessible using</p><pre><a href="http://localhost:8080/api/v1/namespaces/default/services/my-flask-service/proxy/uname">http://localhost:8080/api/v1/namespaces/default/services/my-flask-service/proxy/uname</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*znzeVo9Wyz3Tag8JItrpHA.png" /><figcaption>my-flask service running on EKS Kubernetes cluster</figcaption></figure><h3>Deploy the Kubernetes Web UI Dashboard</h3><p>This part follows <a href="https://docs.aws.amazon.com/eks/latest/userguide/dashboard-tutorial.html">https://docs.aws.amazon.com/eks/latest/userguide/dashboard-tutorial.html</a>.</p><p>Do below steps locally:</p><ul><li>Copy and paste the commands below into your terminal window and type Enter to execute them. These commands download the latest release, extract it, and apply the version 1.8+ manifests to your cluster.</li></ul><pre>DOWNLOAD_URL=$(curl -Ls &quot;<a href="https://api.github.com/repos/kubernetes-sigs/metrics-server/releases/latest">https://api.github.com/repos/kubernetes-sigs/metrics-server/releases/latest</a>&quot; | jq -r .tarball_url)<br>DOWNLOAD_VERSION=$(grep -o &#39;[^/v]*$&#39; &lt;&lt;&lt; $DOWNLOAD_URL)<br>curl -Ls $DOWNLOAD_URL -o metrics-server-$DOWNLOAD_VERSION.tar.gz<br>mkdir metrics-server-$DOWNLOAD_VERSION<br>tar -xzf metrics-server-$DOWNLOAD_VERSION.tar.gz --directory metrics-server-$DOWNLOAD_VERSION --strip-components 1<br>kubectl apply -f metrics-server-$DOWNLOAD_VERSION/deploy/1.8+/</pre><ul><li>Verify that the metrics-server deployment is running the desired number of pods with the following command.</li></ul><pre>$ kubectl get deployment metrics-server -n kube-system<br>NAME             READY   UP-TO-DATE   AVAILABLE   AGE<br>metrics-server   0/1     1            0           27s</pre><ul><li>Use the following command to deploy the Kubernetes dashboard.</li></ul><pre>$ kubectl apply -f <a href="https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml">https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml</a></pre><h4>Create an eks-admin Service Account and Cluster Role Binding</h4><ul><li>Create a file called eks-admin-service-account.yaml with the text below. This manifest defines a service account and cluster role binding called eks-admin.</li></ul><pre>apiVersion: v1<br>kind: ServiceAccount<br>metadata:<br>  name: eks-admin<br>  namespace: kube-system<br>---<br>apiVersion: rbac.authorization.k8s.io/v1beta1<br>kind: ClusterRoleBinding<br>metadata:<br>  name: eks-admin<br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: ClusterRole<br>  name: cluster-admin<br>subjects:<br>- kind: ServiceAccount<br>  name: eks-admin<br>  namespace: kube-system</pre><ul><li>Apply the service account and cluster role binding to your cluster.</li></ul><pre>$ kubectl apply -f eks-admin-service-account.yaml</pre><h4>Connect to Kubernetes dashboard</h4><p>To connect to the Kubernetes dashboard, we need to do below steps:</p><ul><li>Retrieve an authentication token for the eks-admin service account. Copy the <em>&lt;authentication_token&gt;</em> value from the output. You use this token to connect to the dashboard.</li></ul><pre>$ kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep eks-admin | awk &#39;{print $1}&#39;)</pre><ul><li>Start the kubectl proxy if not yet started</li></ul><pre>$ kubectl proxy --port 8080</pre><ul><li>Go to this URL: <a href="http://localhost:8080/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#!/login">http://localhost:8080/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#!/login</a></li><li>It will show you this:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*dk5hRdLB7wgNqIKD5ZKiew.png" /><figcaption>What???</figcaption></figure><p>Let’s explain what just happened. The URL gave us error message no endpoints available for service “kubernetes-dashboard.</p><p>We need to see the detail by issuing this command:</p><pre>$ kubectl get all --namespace kubernetes-dashboard</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*T3XsmQbmQU2yiw_qwBkXPQ.png" /></figure><p>Please note that we add — namespace kubernetes-dashboard argument. The reason is because the dashboard services is deployed using namespace. More on namespace <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/"><strong>here</strong></a>. So there are 2 pods currently in <strong>Pending</strong> state. Let’s dig into more detail for pod/dashboard-metrics-scraper-69fcc6d9df-fbkt7 by describing it.</p><pre>$ kubectl describe pod/dashboard-metrics-scraper-69fcc6d9df-fbkt7 --namespace kubernetes-dashboard</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*Nd5KkluRHjXBec1yhsVGfA.png" /></figure><p>Now, we found the reason. The pods are in Pending state due to insufficient resources. Previously we only deployed 2 EC2 instances.</p><pre>$ kubectl get nodes<br>NAME                                                STATUS   ROLES    AGE    VERSION<br>ip-192-168-45-235.ap-southeast-1.compute.internal   Ready    &lt;none&gt;   102m   v1.14.9-eks-1f0ca9<br>ip-192-168-95-3.ap-southeast-1.compute.internal     Ready    &lt;none&gt;   102m   v1.14.9-eks-1f0ca9</pre><p>So, we need to spin up more resources.</p><p>First, let’s get back to eks.yaml:</p><pre>apiVersion: eksctl.io/v1alpha5<br>kind: ClusterConfig</pre><pre>metadata:<br>  name: my-cluster<br>  region: ap-southeast-1<br>managedNodeGroups:<br>  - name: job-manager<br>    instanceType: t3a.micro<br>    desiredCapacity: 2<br>    minSize: 2<br>    maxSize: 10<br>    tags:<br>      &#39;Project&#39;: &#39;KubernetesNoob&#39;</pre><p>Previously, we tell EKS to spin a cluster with 2 instances as stated in desiredCapacity value.</p><p>Use this command to:</p><pre>$ eksctl get nodegroup --cluster=my-cluster</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*OxGHnwsQr8Bsyo2vYT1wZQ.png" /></figure><p>Now, we want to scale it. Note that the maximum new value is going to be limited by maxSize which is currently set as 10. Let’s scale it to 6 as desired value.</p><pre>$ eksctl scale nodegroup --name=job-manager --cluster=my-cluster --nodes=6</pre><p>While waiting, you can go to your EC2 dashboard and see new instances being provisioned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*0ACNqJHXABhr5dqKvMwYRw.png" /></figure><p>Now, the scaling has been finished. We can verify by using the same command.</p><pre>$ eksctl get nodegroup --cluster=my-cluster</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*qLGPpABGi-gAxI1aCDsPKQ.png" /><figcaption>The nodegroup has been resized</figcaption></figure><p>Let’s check what happened with our kubernetes-dashboard services.</p><pre>$ kubectl get all --namespace kubernetes-dashboard</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*GyjFdQDC0LyedmP0tIIuPA.png" /></figure><p>Horray, the state has been changed into <strong>Running</strong>.</p><p>Let’s try to access the URL: <a href="http://localhost:8080/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#!/login">http://localhost:8080/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#!/login</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*R12JKh_PJHxbk6sBgBJq5w.png" /><figcaption>Put your token and Sign in</figcaption></figure><p>And…..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*ilmEoKchDvmdevpnxDTQCg.png" /></figure><p>That’s your dashboard running!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/0*6GX0fZm3xvFfCJU9.jpg" /></figure><p>This is the <strong>Workload </strong>view containing our my-flask service running using 2 pods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*3kyLwtZnW1zzehJO2DHhpg.png" /></figure><h3>Load Testing</h3><p>The world is not enough without performing some load testing. Let’s use <a href="https://locust.io/"><strong>Locust</strong></a> to test our my-flask app.</p><p>Install Locust using this command:</p><pre>$ pip install locustio</pre><p>Create a new file called locustfile.py and put below code on it.</p><pre>from locust import HttpLocust, TaskSet, task, between</pre><pre>class MyFlaskTasks(TaskSet):<br>    <a href="http://twitter.com/task">@task</a><br>    def about(self):<br>        self.client.get(&quot;/api/v1/namespaces/default/services/my-flask-service/proxy/uname&quot;)</pre><pre>class WebsiteUser(HttpLocust):<br>    task_set = MyFlaskTasks<br>    wait_time = between(5, 15)</pre><p>Run Locust test using this command:</p><pre>$ locust --host=<a href="http://localhost:8080/">http://localhost:8080</a></pre><p>Open your browser and go to <a href="http://localhost:8089/">http://localhost:8089</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*hkOr8mo7X8u6JcHWq2cPfw.png" /></figure><p>Set Number of total users to simulate=20000 and Hatch rate=2000.</p><p>You will see the load is shown in Kubernetes Dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*DsILnlcxfeSyKOif_TMGWA.png" /></figure><p>Please note that this is not intended to show a heavy load testing use case. Instead, it’s showing that we can also use Kubernetes Dashboard to see what happened when the cluster is loaded.</p><h3>Cleaning Up</h3><p>Now, we can clean up all the things we’ve done by simply using this command.</p><pre>$ eksctl delete cluster --region=ap-southeast-1 --name=my-cluster</pre><p>Above command will take care all the clean up process, not limited to:</p><ul><li>Performing clean up CloudFormation stacks</li><li>Deleting EC2 instances</li><li>Deleting EKS cluster</li></ul><p>Note that you will have to manually delete ECR Docker image.</p><h3>Recap</h3><p>So, as a recap:</p><ul><li>We have been creating a simple Kubernetes cluster on Amazon EKS using configuration files</li><li>We have been creating a simple Python Flask webserver and containerized it using Docker</li><li>We have pushed the containerized Flask app into Amazon ECR</li><li>We have been deploying containerized Flask app on Kubernetes</li><li>We have explored on how to use <a href="https://github.com/kubernetes/dashboard">Kubernetes Dashboard</a></li><li>As a bonus, we even do the load testing using Locust</li></ul><p>I hope this article can be useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=213e3e6afc31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Set Up Continuous Integration Pipelines with Gitlab CI on Ubuntu — Part 1]]></title>
            <link>https://taufiq-ibrahim.medium.com/set-up-continuous-integration-pipelines-with-gitlab-ci-on-ubuntu-part-1-5f5808c3efd3?source=rss-6734900d838f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f5808c3efd3</guid>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Taufiq Ibrahim]]></dc:creator>
            <pubDate>Wed, 11 Oct 2017 08:19:12 GMT</pubDate>
            <atom:updated>2017-10-11T08:19:29.824Z</atom:updated>
            <content:encoded><![CDATA[<p>This series shall guides you for setting up Gitlab CI on Ubuntu. The first part of the series covers how to set up Gitlab CE. Gitlab Runner shall be covered on the second part of this series.</p><h3>Prerequisites</h3><p>The <a href="http://docs.gitlab.com/ee/install/requirements.html#hardware-requirements">published GitLab hardware requirements</a> recommend using a server with:</p><ul><li>2 cores</li><li>4GB of RAM</li></ul><h3>Installing the Dependencies</h3><pre>sudo apt-get update</pre><pre>sudo apt-get install ca-certificates curl openssh-server postfix</pre><h3>Install Gitlab CE</h3><p>Move into the /tmp directory and then download the installation script.</p><p>For Ubuntu/Debian :</p><pre>cd /tmp</pre><pre>curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh</pre><p>To examine the sh script, use following command.</p><pre>less /tmp/script.deb.sh</pre><p>Once you are satisfied with the safety of the script, run the installer:</p><pre>sudo bash /tmp/script.deb.sh</pre><p>If the installer successfully ran, now we can run the actual Gitlab CE installer by issuing following command.</p><pre>sudo apt-get install gitlab-ce</pre><p>Before you can use the application, however, you need to run an initial configuration command.</p><pre>sudo gitlab-ctl reconfigure</pre><p>This is the success sample snapshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*xLHhB3K3VgSqPUcciElmIQ.png" /></figure><h3>Accessing Gitlab CE Web Interface</h3><p>Now you can try to access Gitlab CE web interface by opening your browser to <a href="https://host/">http://host</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YTEkxZnNvllxtVsEPaU0oA.png" /></figure><p>Gitlab ask you to change the administrative account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_I3JFjP-tBr0O0J_PiH_Wg.png" /></figure><p>Now you can login using credential:</p><ul><li>Username or email: <strong>root</strong></li><li>Password: [<em>the password you create earlier for administrative account</em>]</li></ul><h3>Summary</h3><ul><li>We have a machine running Gitlab CE. We can use this for building and committing our apps code.</li><li>On the next article, we will cover how to set up Gitlab Runner on different machine.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f5808c3efd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Airflow Installation on Ubuntu]]></title>
            <link>https://taufiq-ibrahim.medium.com/apache-airflow-installation-on-ubuntu-ddc087482c14?source=rss-6734900d838f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddc087482c14</guid>
            <category><![CDATA[etl]]></category>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Taufiq Ibrahim]]></dc:creator>
            <pubDate>Mon, 02 Oct 2017 02:31:46 GMT</pubDate>
            <atom:updated>2017-10-11T05:40:45.715Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the documentation of Apache Airflow installation using Ubuntu on Windows.</p><h3>Preparation</h3><h4>pip</h4><p>Apache Airflow requires <em>pip</em> for installation. Run below command.</p><pre>sudo apt-get install python-pip</pre><p>Perhaps if the default installed pip is not the up-to-date version, you may want to consider updating it:</p><p>sudo pip install --upgrade pip</p><h4>Installing Database Backend (PostgreSQL)</h4><pre>sudo apt-get install postgresql postgresql-contrib</pre><p>Now we already have Postgres installed. Next, we need to create</p><ul><li>a database for Airflow</li><li>a user having access to the database</li></ul><h4>Creating Postgres User and Database</h4><ul><li>Creating new Linux user <em>airflow</em>.</li></ul><pre>sudo adduser airflow<br>[sudo] password for tole:<br>Adding user `airflow’ …<br>Adding new group `airflow’ (1001) …<br>Adding new user `airflow’ (1001) with group `airflow’ …<br>Creating home directory `/home/airflow’ …<br>Copying files from `/etc/skel’ …<br>Enter new UNIX password:<br>Retype new UNIX password:<br>passwd: password updated successfully<br>Changing the user information for airflow<br>Enter the new value, or press ENTER for the default<br> Full Name []: airflow<br> Room Number []:<br> Work Phone []:<br> Home Phone []:<br> Other []:<br>Is the information correct? [Y/n] Y</pre><ul><li>Use <em>usermod</em> to add new user <em>airflow </em>into the <em>sudo</em> group.</li></ul><pre>sudo usermod -aG sudo airflow</pre><ul><li>Now we change the shell into user <em>airflow</em>.</li></ul><pre>su - airflow</pre><ul><li>Now we use user <em>postgres</em> to create psql role for <em>airflow.</em></li></ul><pre>sudo -u postgres psql</pre><p>Note: when I run above line in Ubuntu on Windows, error was thrown like below:</p><pre>sudo: setresuid() [1000, 113, 1000] -&gt; [-1, 0, -1]: Operation not permitted<br>sudo: unable to set runas group vector: Operation not permitted<br>sudo: PERM_ROOT: setresuid(0, -1, 0): Operation not permitted</pre><p>Temporary solution was using:</p><pre>user@server:~$sudo su postgres<br>postgres@server:/home/user$ psql</pre><p>Now we’re in <strong>postgres=#</strong></p><p>Let’s create Postgres user for <em>airflow</em>. Still in <em>psql</em> console.</p><pre>postgres=# CREATE USER airflow PASSWORD ‘a1rfl0w’;<br>CREATE ROLE<br>postgres=# CREATE DATABASE airflow;<br>CREATE DATABASE<br>postgres=# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO airflow;<br>GRANT<br>postgres=# \du<br> List of roles<br> Role name | Attributes | Member of<br> — — — — — -+ — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — + — — — — — -<br> airflow | | {}<br> postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}</pre><p>Now let’s try to check wether the database already set up and can be accessed by user <em>airflow</em>.</p><pre>psql -d airflow<br>psql (9.5.9)<br>Type &quot;help&quot; for help.</pre><pre>airflow=&gt; \conninfo<br>You are connected to database &quot;airflow&quot; as user &quot;airflow&quot; via socket in &quot;/var/run/postgresql&quot; at port &quot;5432&quot;.<br>airflow=&gt;</pre><p>If something like above shown, then you’re good.</p><h4>Change pg_hba.conf Setting</h4><p>We also need to reconfigure <strong>pg_hba.conf </strong>to allow connection from airflow.</p><pre>sudo nano /etc/postgresql/9.5/main/pg_hba.conf</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*UUIkn3n_5CYweny7rKHN4Q.png" /></figure><p>Change IPV4 address to 0.0.0.0/0 and the IPV4 method to trust.</p><pre># IPv4 local connections:<br>host all all 0.0.0.0/0 trust</pre><pre><strong>// Restart the service</strong><br>sudo service postgresql restart</pre><p>Next, we configure <strong>postgresql.conf</strong>.</p><pre>sudo nano /etc/postgresql/9.5/main/postgresql.conf</pre><pre># — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — <br># CONNECTIONS AND AUTHENTICATION<br># — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — </pre><pre># — Connection Settings -</pre><pre>#listen_addresses = ‘localhost’ # what IP address(es) to listen on;<br>listen_addresses = ‘*’ # for Airflow connection</pre><pre><strong>// Restart the service</strong><br>sudo service postgresql restart</pre><h3>Airflow Installation</h3><h4>Set Up Airflow Default Home</h4><pre>export AIRFLOW_HOME=~/airflow</pre><h4>Installing Airflow</h4><pre>pip install &quot;[airflow[postgres, mssql, celery, rabbitmq]&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*gZN1Bihc-uaW-cYvJttDKg.png" /></figure><p>Check <a href="https://airflow.incubator.apache.org/installation.html#extra-packages">here </a>or more details on the list of the subpackages and what they enable.</p><h4>Starting Up Airflow Database</h4><p>After successful packages installation, we can start Airflow’s database by issuing:</p><pre>airflow initdb</pre><p>The command will generate airflow.cfg file in Airflow’s home directory we set up earlier.</p><h4>Set up airflow.cfg</h4><ul><li>we should use CeleryExecutor instead of SequentialExecutor if we want to run the pipeline in the webUI</li></ul><pre>executor = CeleryExecutor</pre><ul><li>we should pass along the connection info of the postgresql database airflow we just created</li></ul><pre>sql_alchemy_conn = postgresql+psycopg2://ubuntu@localhost:5432/airflow</pre><p>Save it and run airflow initdb</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TCvYqggBvIXd55EfMSbxBg.png" /></figure><h4>Disabling Examples</h4><pre>nano airflow/airflow.cfg</pre><pre>....</pre><pre># Whether to load the examples that ship with Airflow. It’s good to<br># get started, but you probably want to set this to False in a production<br># environment<br>load_examples = False</pre><h4>Starting Airflow Web Server</h4><p>This command will start web server in your localhost at port 8080.</p><pre>airflow webserver</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fRo1BXAXhT41BhFKeOUz1Q.png" /></figure><p>Next. We will cover how to integrate Airflow with Microsoft SQL Server database.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddc087482c14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Apache JMeter on Windows 10]]></title>
            <link>https://taufiq-ibrahim.medium.com/installing-apache-jmeter-on-windows-10-62b7f53841f?source=rss-6734900d838f------2</link>
            <guid isPermaLink="false">https://medium.com/p/62b7f53841f</guid>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[load-testing]]></category>
            <category><![CDATA[jmeter]]></category>
            <category><![CDATA[windows]]></category>
            <dc:creator><![CDATA[Taufiq Ibrahim]]></dc:creator>
            <pubDate>Wed, 27 Sep 2017 06:59:42 GMT</pubDate>
            <atom:updated>2017-09-27T06:59:42.924Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the documentation for Apache JMeter installation on Windows 10.</p><p>Disclaimer:</p><ul><li>This article was written on September 2017</li><li>Latest version of Apache JMeter was 3.3</li><li>Java 8 was required</li><li>My Windows 10 did not have any Java installed</li></ul><h3>Step 1: Install Java 8</h3><p>Download latest Java 8 from Oracle website. You will need to have Oracle account for downloading Java.</p><p>Run the Java installer package.</p><p>Verify installed Java version by running this command on Command Prompt.</p><pre>java -version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*pjJl97zPSd2BJ2wx5FGXzA.png" /></figure><h3>Step 2: Download Apache JMeter</h3><p>You can download the latest version of Apache JMeter from <a href="http://jmeter.apache.org/download_jmeter.cgi">http://jmeter.apache.org/download_jmeter.cgi</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RpoNb7yOVTY_4Fv_-i6jmQ.png" /></figure><p>Download the Binaries zip file.</p><h3>Step 3: Extract Apache JMeter</h3><p>Find the downloaded zip file and extract it to your desired directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*2SmH7XCiyIdvITCpnkS48g.png" /><figcaption>Downloaded zip file</figcaption></figure><p>For example, I extract the <strong><em>apache-jmeter-3.3.zip</em></strong> to <strong><em>C:\tole\</em></strong>.</p><p>This is the snapshot of the extracted directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*5Ux5fY9v95mUceFmMNPCsg.png" /><figcaption>Apache JMeter extracted directory</figcaption></figure><p>Now go to <strong>/<em>bin</em></strong> folder. You will find <strong><em>jmeter.bat</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*GgYm9MuFibuNaeJb3eH28g.png" /><figcaption>/bin directory</figcaption></figure><p>Double click on that file. The Apache JMeter GUI will be opened. You can create a shortcut for it on your desktop too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RyP0DlhEOx58pk2_t2O8wg.png" /><figcaption>Apache JMeter GUI</figcaption></figure><p>That’s it!</p><p>On the next article, I will show how to use Apache JMeter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62b7f53841f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ubuntu On Windows 10]]></title>
            <link>https://taufiq-ibrahim.medium.com/ubuntu-on-windows-10-a7a23a6c8f14?source=rss-6734900d838f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7a23a6c8f14</guid>
            <category><![CDATA[windows-10]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Taufiq Ibrahim]]></dc:creator>
            <pubDate>Fri, 01 Sep 2017 09:51:54 GMT</pubDate>
            <atom:updated>2017-09-01T09:51:54.308Z</atom:updated>
            <content:encoded><![CDATA[<h3>Requirements</h3><ul><li>Your PC must be running a 64-bit version of Windows 10 Anniversary Update or later (build 1607+)</li></ul><h3>Read These Links Before Begin</h3><p><a href="https://msdn.microsoft.com/en-us/commandline/wsl/install_guide">Install the Linux Subsystem on Windows 10</a></p><h4>Install the Windows Subsystem for Linux</h4><p>Open PowerShell as Administrator and run:</p><pre>Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux</pre><p>Restart your computer if asked.</p><h4>Getting Ubuntu Started</h4><p>Open PowerShell or Command Prompt as Administrator and run</p><pre>bash</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*4E6LjMkYG1HPPQEWyIyghA.png" /></figure><p>If the command ask to enable the Developer Mode, then do these:</p><ul><li>Go to Setting → Update &amp; Security → For developers</li><li>Choose Developer mode on Use developer features setting</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zOe08rX_yyKmxV6QulRhEg.png" /></figure><ul><li>Click Yes</li><li>The process will take a while to complete</li></ul><p>Open PowerShell or Command Prompt as Administrator and run</p><pre>bash</pre><p>Type “y” to continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*ngXKDVuiKZNMRX9QTBLQ1A.png" /></figure><p>This will download the Ubuntu package from the Windows Store. Grab your coffee or do some stretching because it will take a while to complete depends on your connection.</p><p>Windows will take care of the rest. You just need to fill new UNIX user name and password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSW9kS2WsNk_YK47GDp38A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7a23a6c8f14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[500 Meter Rectangular Grids Using PostgreSQL]]></title>
            <link>https://taufiq-ibrahim.medium.com/500-meter-rectangular-grids-using-postgresql-202b13aa6ba0?source=rss-6734900d838f------2</link>
            <guid isPermaLink="false">https://medium.com/p/202b13aa6ba0</guid>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Taufiq Ibrahim]]></dc:creator>
            <pubDate>Tue, 01 Aug 2017 22:56:21 GMT</pubDate>
            <atom:updated>2019-02-18T09:18:18.028Z</atom:updated>
            <content:encoded><![CDATA[<p>Suddenly yesterday afternoon my client asked me to create a report involving 500 meter rectangular grid. Well, that was quite massive, since the data is covering the whole Indonesia. Yes, the whole Indonesia.</p><p>Indonesia is basically a very large area. Spread in extent 94 to 141 deg longitude and 6 deg north to 11 deg south in latitude.</p><p>First attempt using Mapinfo was a total failure. Mapinfo refuse to process due to the number of records was to large.</p><p>Second attempt using QGIS’ Vector Grid faced with difficulties in coordinate projection.</p><p>Third attempt using SQL Server spatial feature was also a failure. I could not find any method to translate the geometry.</p><p>So, I went back to PostgreSQL. In a matter of minutes of Google search, I found a function to create the grids.</p><p>This is the original codes, I copied it from <a href="https://gis.stackexchange.com/questions/16374/how-to-create-a-regular-polygon-grid-in-postgis">here</a>. Just run it and the function shall be created on the PostgreSQL database.</p><pre>CREATE OR REPLACE FUNCTION ST_CreateFishnet(<br>        nrow integer, ncol integer,<br>        xsize float8, ysize float8,<br>        x0 float8 DEFAULT 0, y0 float8 DEFAULT 0,<br>        OUT &quot;row&quot; integer, OUT col integer,<br>        OUT geom geometry)<br>    RETURNS SETOF record AS<br>$$<br>SELECT i + 1 AS row, j + 1 AS col, ST_Translate(cell, j * $3 + $5, i * $4 + $6) AS geom<br>FROM generate_series(0, $1 - 1) AS i,<br>     generate_series(0, $2 - 1) AS j,<br>(<br>SELECT (&#39;POLYGON((0 0, 0 &#39;||$4||&#39;, &#39;||$3||&#39; &#39;||$4||&#39;, &#39;||$3||&#39; 0,0 0))&#39;)::geometry AS cell<br>) AS foo;<br>$$ LANGUAGE sql IMMUTABLE STRICT;</pre><p>This is how to call the function.</p><pre>SELECT *<br>FROM ST_CreateFishnet(4, 6, 10, 10) AS cells;</pre><p>However, I faced a problem. I found it’s hard to generate grid in meters and using SRID 4326.</p><p>So, I did some hack and changes a bit of the codes like this.</p><pre>CREATE OR REPLACE FUNCTION ST_CreateFishnet(<br> nrow integer, --1<br> ncol integer, --2<br> xsize numeric(19,9), --3<br> ysize numeric(19,9), --4<br> x0 numeric(19,9) DEFAULT 0, --5 <br> y0 numeric(19,9) DEFAULT 0, --6<br> OUT “row” integer, <br> OUT col integer,<br> OUT geom geometry)<br> RETURNS SETOF record AS<br>$$<br>SELECT i + 1 AS row, j + 1 AS col, <br>ST_Translate(<br> cell<br>, j * $3 + $5, i * $4 + $6<br>)<br>AS geom<br>FROM generate_series(0, $1 - 1) AS i,<br> generate_series(0, $2 - 1) AS j,<br>(<br><strong>SELECT ST_PolygonFromText(&#39;POLYGON((0 0, 0 &#39;||$4||&#39;, &#39;||$3||&#39; &#39;||$4||&#39;, &#39;||$3||&#39; 0,0 0))&#39;, 4326) AS cell</strong><br>) AS foo;<br>$$ LANGUAGE sql IMMUTABLE STRICT;</pre><p>Still I had one more problem. SRID 4326 projection requires ST_Translate to work in degree unit, not in meters!</p><p>So, I did a search how to convert meter to degree. This <a href="https://en.wikipedia.org/wiki/Decimal_degrees">Wikipedia link</a> nailed it. In equatorial — just where Indonesia is — this numbers should work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*KGwmeXtcTghJW_MyuanxXQ.png" /></figure><p>In theory, I could just use 500 meter / 1.1132 meter * 0.00001, which equal to . So, I blindly tried to run the SQL, with small number of data.</p><pre>INSERT INTO idn_grid_500m SELECT *<br>FROM ST_CreateFishnet(10, 10, 0.00449155587495509, 0.00449155587495509, 92, 8) AS cells;</pre><p>I was surprised that after I run a sample script, the resulting polygons were only 495 meters in size. I am stucked, again.</p><p>Another hack must be done. I did a brutal force by manually changing the number. Luckily, I found the perfect number. It was <strong>0.00453</strong>.</p><p>Ran the SQL again, the result was almost perfect and I can live with it.</p><pre>INSERT INTO idn_grid_500m SELECT *<br>FROM ST_CreateFishnet(4645, 11458, 0.00453, 0.00453, 92, 8) AS cells;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=202b13aa6ba0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>