<?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 Deva Pramod on Medium]]></title>
        <description><![CDATA[Stories by Deva Pramod on Medium]]></description>
        <link>https://medium.com/@deva-pramod?source=rss-33a817e431ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qpoTRc8l-QQM17Rm6Seqfw.jpeg</url>
            <title>Stories by Deva Pramod on Medium</title>
            <link>https://medium.com/@deva-pramod?source=rss-33a817e431ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:18:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deva-pramod/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[Running SQL queries on Dynamo DB through Athena]]></title>
            <link>https://medium.com/@deva-pramod/running-sql-queries-on-dynamo-db-through-athena-a976be096fe9?source=rss-33a817e431ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/a976be096fe9</guid>
            <category><![CDATA[glue]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[athena]]></category>
            <dc:creator><![CDATA[Deva Pramod]]></dc:creator>
            <pubDate>Tue, 04 Jul 2023 17:12:29 GMT</pubDate>
            <atom:updated>2023-07-04T17:14:35.253Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*pxcouT3X9M5r-B4HhZifKQ.jpeg" /></figure><h3>Introduction</h3><p>Athena is a service that allows you to run SQL queries on different data sources like Amazon S3. However Athena doesn’t support Dynamo DB as a data source. In order to circumvent this issue, we will use some of the glue services and store data in parquet format in S3.</p><h3>Dynamo DB Crawler</h3><p>A glue crawler is a tool to populate a Glue Data Catalog. An AWS glue data catalog is a database that can have multiple tables. Each table can have the schema or index of where and how data is stored in a particular data source. This data can be populated using a glue crawler.</p><ol><li>Configure a glue data catalog</li></ol><pre>CrawlerDatabase:<br>    Type: AWS::Glue::Database<br>    Properties:<br>      CatalogId: !Ref AWS::AccountId<br>      DatabaseInput:<br>        Name: DynamoDBCrawler<br>        Description: Database for crawler</pre><p>The DatabaseInput field is to will be where the dynamo db schema will be stored. CatalogId is the AWS account id.</p><p>2. Configure a Crawler for Dynamo DB</p><p>The role required can make use of AWSGlueServiceRole Managed Policy Arn with glue.amazonaws.com as principal. Other Permissions related to Dynamo DB include</p><ul><li>GetItem</li><li>Scan</li><li>DescribeTable</li><li>Query</li></ul><pre>DynamoDBCrawler:<br>    Type: AWS::Glue::Crawler<br>    Properties:<br>      Name: dynamoDBCrawler<br>      DatabaseName: // Name of glue data catalog database<br>      Role: // Role with Dynamo DB and Glue Service Role<br>      Targets:<br>        DynamoDBTargets: <br>          - Path: // Enter name of Dynamo Database</pre><p>Defining the target of a crawler tells it which data source to crawl. On running, this will create a table with the same name as that of Dynamo DB.</p><h3>Glue Job to update Data in parquet format</h3><p>To deploy a glue job, it is imperative to write a python script to tell it what to do. Refer here : <a href="https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-intro-tutorial.html">https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-intro-tutorial.html</a></p><p>Basically it can have three nodes. One dynamic node referencing data catalog database with the name of Dynamo Db. A second node to apply mapping. A third node to write it in parquet format. Learn more about parquet format here: <a href="https://www.snowflake.com/guides/what-parquet#:~:text=Parquet%20is%20an%20open%20source,wide%20variety%20of%20encoding%20types">https://www.snowflake.com/guides/what-parquet#:~:text=Parquet%20is%20an%20open%20source,wide%20variety%20of%20encoding%20types</a>..</p><p>This python script needs to be stored in a S3 bucket. This can be done through AWS console or as I prefer it using AWS CLI.</p><pre>aws s3 cp filename.txt s3://bucket-name</pre><p>After uploading the script to the bucket, you can reference it in the Glue Job like,</p><pre>GlueJob:<br>    Type: AWS::Glue::Job<br>    Properties:<br>      Name: // Job Name<br>      GlueVersion: &#39;3.0&#39;<br>      Command: <br>        Name: glueetl<br>        ScriptLocation: s3://script-location-glue/script.py<br>      Role: // Role with S3 Read and write access and glue service role</pre><p>The Role should have a AWSGlueServiceRole and S3 Read and Write Access.</p><h3>S3 Crawler</h3><p>Once the Job is complete, we can use a crawler to define the schema in glue data catalog table. This table can be part of the same data catalog Database defined above for the dynamo db.</p><pre> S3Crawler:<br>    Type: AWS::Glue::Crawler<br>    Properties:<br>      Name: s3Crawler<br>      DatabaseName: // Name of glue data catalog database<br>      Role: // Role with Glue Service role and S3 access<br>      Targets:<br>        S3Targets:<br>          - Path: // Name of S3 bucket</pre><h3>Step Functions to run it all</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*wKE21Ltdv_AXEpaDI-xLcA.png" /></figure><p>Using Glue Jobs with step functions is pretty straightforward. AWS Step Functions will wait for the Glue Job to complete when you add ‘.sync’ to Resource section.</p><pre>RunGlueJob:<br>  Type: Task<br>  Parameters: <br>    JobName: !Ref GlueJob<br>  Resource: arn:aws:states:::glue:startJobRun.sync<br>  Next: UploadDataInParquetFormat</pre><p>However Running crawlers is not as straightforward. It will require adding a get crawler request and using a choice state to check whether the crawler is running or not. And crawler tasks are run through aws-sdk.</p><pre>arn:aws:states:::aws-sdk:glue:getCrawler</pre><p>The Choice state can check for the variable $.Crawler.State for READY to see if the crawler has stopped running. Adding a wait and can help reduce unnecessary requests.</p><p>After a workflow execution, you are good to run queries after selecting the name of the S3 bucket from the Athena console. Or you can use aws-sdk for Athena to run queries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a976be096fe9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy a Docker container with Fargate]]></title>
            <link>https://medium.com/@deva-pramod/deploy-a-docker-container-on-fargate-through-serverless-framework-a7e62717dfc?source=rss-33a817e431ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7e62717dfc</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[lambda]]></category>
            <dc:creator><![CDATA[Deva Pramod]]></dc:creator>
            <pubDate>Sat, 17 Jun 2023 10:16:02 GMT</pubDate>
            <atom:updated>2026-01-12T17:45:42.605Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Lambda invokes ECS task with container image uploaded on ECR. The ECS is scaled and maintained by Fargate" src="https://cdn-images-1.medium.com/max/376/1*AeTuL2dFDbadBVez9wYy1Q.jpeg" /></figure><p>Amazon Elastic Container Service or (ECS) is a fully managed container orchestration service that allows you to host containers in AWS cloud. Fargate is a technology that manages the ECS clusters and scales according to load.</p><p>When compared to Compute Primitives like Lamdba and EC2, fargate has the following advantages —</p><ol><li>Can Handle long running tasks whereas lambda shuts down in 15 minutes</li><li>Faster startup and teardown than EC2</li><li>Cost efficiency for containerized workloads (Pay-as-you-go model)</li></ol><h3>Creating the Docker file</h3><p>Dockerfile is a file that is responsible for all the configuration of the container image. Below is a sample Dockerfile for running a node JS application.</p><pre>FROM node:16<br><br>WORKDIR /app<br><br>COPY package*.json ./<br><br>RUN npm install<br><br>COPY . .<br><br>CMD [ &quot;npm&quot;, &quot;start&quot; ]</pre><p>For locally running on Mac Silicon Chips, use ` <em>— platform=linux/amd64</em>` tag either in FROM or while runing docker.</p><p>ℹ️ Pro tip → Use a lightweight distro like alpine linux for better performance.</p><h3>ECR repository</h3><p>ECR stands for Elastic Container Repository, it is a repository service from AWS that allows it to upload container images.</p><pre>  ECR:<br>    Type: AWS::ECR::Repository<br>    Properties:<br>      RepositoryName: repository-name</pre><p>To push a docker container image into Elastic Container, first login through shell with this command.</p><pre>aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_ARN</pre><p>Once logged in, it’s time to build the docker image. The following file will build the file with the latest tag.</p><pre>docker build -t {name}:latest .</pre><p>Pushing to Elastic Container Service</p><pre>docker push $ECR_ARN/{conatiner-name}:latest</pre><h3>ECS task</h3><p>ECS or Elastic Container Service task definition specifies the image to use with each container in the task and CPU and memory to allocate.</p><pre> TaskDefintion: <br>    Type: AWS::ECS::TaskDefinition<br>    Properties: <br>      ExecutionRoleArn:<br>        Fn::GetAtt:<br>          - TaskExecutionRole<br>          - Arn<br>      ContainerDefinitions: <br>        - <br>          Name: task-defintion-name<br>          Image: ECR repository URI<br>          logConfiguration:<br>            logDriver: awslogs<br>            options:<br>              awslogs-group: group name<br>              awslogs-region: region<br>              awslogs-create-group: true<br>          Cpu: 256<br>          Memory: 512<br>          Essential: true<br>      Cpu: 256<br>      Memory: 512<br>      NetworkMode: awsvpc<br>      RequiresCompatibilities: <br>        - FARGATE<br>      TaskRoleArn:<br>        Fn::GetAtt:<br>          - TaskExecutionRole<br>          - Arn</pre><p>Adding Fargate as required compatibility is responsible for scaling and maintaining the underlying infrastructure for running ECS task.</p><h3>ECS cluster</h3><p>ECS cluster is responsible for handling the ECS tasks. If one task fails the cluster will spin another one up. If you need N number of tasks running at the same time — change the Weight value accordingly.</p><pre>  Cluster:<br>    Type: AWS::ECS::Cluster<br>    Properties:<br>      ClusterName: cluster-name<br>      CapacityProviders:<br>        - FARGATE<br>      DefaultCapacityProviderStrategy:<br>        - CapacityProvider: FARGATE<br>          Weight: 1</pre><h3>Create lambda to trigger ECS task and to set env variables</h3><p>Finally write a lambda to trigger an ECS task and pass on any env variables required to run the container. The lambda can be configured to run as cron or on http invocation. The Lambda is also responsible for passing the role. The IAM role for lambda can have the iam:passrole action which allows it pass the role on to the container task on trigger.</p><p>So when ECS needs a permission, we assign it to lambda and then pass it to ECS.</p><p>The role for the lambda function should have the following policies -&gt;</p><pre>  LambdaRole:<br>    Type: AWS::IAM::Role<br>    Properties:<br>      RoleName: LambdaRole<br>      AssumeRolePolicyDocument:<br>        Version: &quot;2012-10-17&quot;<br>        Statement:<br>          - Effect: Allow<br>            Principal:<br>              Service: &quot;lambda.amazonaws.com&quot;<br>            Action: &quot;sts:AssumeRole&quot;<br>      Policies:<br>        - PolicyName: ECSInvokeAccess<br>          PolicyDocument:<br>            Version: &quot;2012-10-17&quot;<br>            Statement:<br>              - Action:<br>                  - &quot;ecs:RunTask&quot;<br>                Effect: Allow<br>                Resource:<br>                  - &quot;ecs:task:arn&quot;<br>        - PolicyName: LambdaAllowIamPassRole<br>          PolicyDocument:<br>            Version: &quot;2012-10-17&quot;<br>            Statement:<br>              - Action:<br>                  - &quot;iam:PassRole&quot;<br>                Effect: &quot;Allow&quot;<br>                Resource: &quot;*&quot; </pre><p>Starting the ECS Task with <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html">https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html</a></p><pre>  const params = {<br>    cluster: CLUSTER_NAME,<br>    launchType: &#39;FARGATE&#39;,<br>    taskDefinition: arn:aws:ecs:{region}:{accountId}:cluster/{name},<br>    count: 1,<br>    platformVersion: &#39;LATEST&#39;,<br>    networkConfiguration: {<br>      awsvpcConfiguration: {<br>        assignPublicIp: &#39;ENABLED&#39;,<br>        securityGroups: [SECURITY_GROUP_ID],<br>        subnets: [SUBNET_ID]<br>      }<br>    },<br>    startedBy: &#39;lambdaName&#39;,<br>    overrides: {<br>      containerOverrides: [<br>        {<br>          name: CONTAINER_NAME,<br>          environment: loadEnv<br>        }<br>      ]<br>    }<br>  }<br><br>  const command = new RunTaskCommand(params)<br>  await client.send(command)</pre><p>ℹ️ Pro tip -&gt; Use the containerOverrides options to set environment variables in ECS. Make sure this is an array of objects with</p><pre>{<br>   name: &lt;string&gt;,<br>   value: &lt;string&gt;<br>}</pre><h3>Running CRON Jobs with ECS</h3><p>Cron Jobs cannot be configured directly in ECS. It is configured in AWS Eventbridge service. Eventbridge can configure cron patterns like [cron(0 16 * * ? *)] or verbose expressions like rate (1 day).</p><p>Checkout the rule patterns here — <a href="https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-scheduled-rule-pattern.html">https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-scheduled-rule-pattern.html</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*D_3uMFBJHN56_x3ObIZ4vw.jpeg" /></figure><p>The Eventbridge managed service will invoke the lambda which will than run the task on the Elastic Container Service. The lambda will be shut down as soon as ECS Run Task Command is executed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7e62717dfc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>