<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shubham Pawar</title>
    <description>The latest articles on DEV Community by Shubham Pawar (@shubhampawar).</description>
    <link>https://dev.to/shubhampawar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F631581%2Ff65bddda-37f5-404f-b2d5-76dac721d43d.jpeg</url>
      <title>DEV Community: Shubham Pawar</title>
      <link>https://dev.to/shubhampawar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shubhampawar"/>
    <language>en</language>
    <item>
      <title>Create AWS Step Function and Lambda using Terraform and GitLab CI</title>
      <dc:creator>Shubham Pawar</dc:creator>
      <pubDate>Thu, 25 Aug 2022 08:09:38 +0000</pubDate>
      <link>https://dev.to/shubhampawar/setup-aws-step-function-and-lambda-with-terraform-and-gitlab-ci-1i8b</link>
      <guid>https://dev.to/shubhampawar/setup-aws-step-function-and-lambda-with-terraform-and-gitlab-ci-1i8b</guid>
      <description>&lt;h2&gt;
  
  
  Install Terraform
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download Terraform binary and unzip the package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set terraform path to unzipped binary location. Terraform runs as a single binary named terraform. Any other files in the package can be safely removed and Terraform will still function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verify the setup by using command terraform version in CLI.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install AWS CLI
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download and run the &lt;a href="https://awscli.amazonaws.com/AWSCLIV2.msi" rel="noopener noreferrer"&gt;AWS CLI&lt;/a&gt; MSI installer for Windows (64-bit):&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To confirm the installation, open the Start menu, search for cmd to open a command prompt window, and at the command prompt use the aws --version command.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h2&gt;
  
  
  Build a infrastructure
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a directory for your configuration  &lt;code&gt;mkdir terraform&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Change the directory and create a file &lt;em&gt;main.tf&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Initialize the directory with &lt;code&gt;terraform init&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Run &lt;code&gt;terraform plan&lt;/code&gt; to see any changes are required for 
infrastructure.&lt;/li&gt;
&lt;li&gt;Format and validate the configuration
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxb6syq77z2qp06ktu92x.png" alt="3"&gt;
&lt;/li&gt;
&lt;li&gt;Apply the configuration now with the &lt;code&gt;terraform apply&lt;/code&gt; command.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h2&gt;
  
  
  Configuring Gitlab CI for Terraform
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a file on the root of your repository called .gitlab-ci.yml&lt;/li&gt;
&lt;li&gt;Get your access key ID and secret access key.&lt;/li&gt;
&lt;li&gt;Set aws variables go to - gitlab project → settings → CI/CD → Variables&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;         &lt;/p&gt;

&lt;h2&gt;
  
  
  Sample GitLab pipeline
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stages:
  - validate
  - plan
  - apply
  - destroy
image:
  name: hashicorp/terraform:light
  entrypoint:
    - '/usr/bin/env'
    - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
before_script:
  - export AWS_ACCESS_KEY=${AWS_ACCESS_KEY_ID}
  - export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
  - rm -rf .terraform
  - cd terraform/
  - terraform --version
  - terraform init

validate:
  stage: validate
  script:
    - terraform validate
  only:
    - branches

plan:
  stage: plan
  script:
    - terraform plan -out "planfile"
  dependencies:
    - validate
  artifacts:
    paths:
      - planfile

apply:
  stage: apply
  script:
    - terraform apply -input=false "planfile"
  dependencies:
    - plan
  when: manual
  only:
    - main

destroy:
  stage: destroy
  script:
    - echo "Destroying resources"
    - terraform destroy -state=$STATE --auto-approve
  dependencies:
    - apply
  when: manual
  only:
    refs:
      - main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/shubhampawar/terraform_POC" rel="noopener noreferrer"&gt;Sample terraform code for lambda and step function&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>terraform</category>
      <category>stepfunction</category>
      <category>lambda</category>
    </item>
    <item>
      <title>What is AWS CDK &amp; Why to use it?</title>
      <dc:creator>Shubham Pawar</dc:creator>
      <pubDate>Wed, 22 Jun 2022 06:38:03 +0000</pubDate>
      <link>https://dev.to/epam_india_python/what-is-aws-cdk-why-to-use-it-1l8m</link>
      <guid>https://dev.to/epam_india_python/what-is-aws-cdk-why-to-use-it-1l8m</guid>
      <description>

&lt;h3&gt;
  
  
  What Is AWS CDK?
&lt;/h3&gt;

&lt;p&gt;The AWS Cloud Development Kit (AWS CDK) is an open-source software development framework for defining cloud infrastructure as code (IaC) and provision it through AWS CloudFormation. It was introduced in July 2019.It has all the advantages of CloudFormation and IaC can be provisioned using modern programming languages like Typescript, C# (C-Sharp), Java, and Python. &lt;/p&gt;

&lt;h3&gt;
  
  
  Why to use CDK
&lt;/h3&gt;

&lt;p&gt;In AWS CDK reusable components can be designed that meet organizational security policy, compliance needs and other requirements, also as any other software library this can be shared easily around the organization, enabling bootstrapping of new projects with best practices by default.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  CDK use a template file to create and delete a collection of resources together as a single unit (a stack).&lt;/li&gt;
&lt;li&gt;  Use the AWS CDK to define your cloud resource in a familiar programing language which CDK supports.&lt;/li&gt;
&lt;li&gt;  It provides high-level components that preconfigure cloud resources with proven defaults, helping you build on AWS without needing to be an expert&lt;/li&gt;
&lt;li&gt;You can use your favorite IDE and can take the advantage of existing productivity tools and testing frameworks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The two main building blocks of AWS CDK
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stacks&lt;/strong&gt;&lt;br&gt;
Stacks are basic units of deployment in AWS CDK that are composable. Single or multiple stacks can be used in a project. A stack can share values by consuming resources from another stack. Behind the scenes, CDK uses the Cloudformation import value to pass around different Cloudformation stacks.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Constructs&lt;/strong&gt;&lt;br&gt;
Constructs are the basic building blocks of AWS CDK apps. A construct represents a "cloud component" and encapsulates everything AWS Cloudformation needs to create the component. A construct can be an Amazon Simple Storage Service (S3) bucket, or any other related AWS resources. AWS CDK have a collection of constructs which is called AWS construct library. Constructs code can be reused throughout infrastructure project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting up CDK-&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install or update the AWS CDK CLI from npm (requires &lt;a href="https://nodejs.org/download/release/latest-v14.x/" rel="noopener noreferrer"&gt;Node.js ≥ 14.15.0&lt;/a&gt;)&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g aws-cdk
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Initialize a project:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir CDK_Demo
cd CDK_Demo
cdk init app --language=python
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;This will create a sample project.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Use &lt;code&gt;cdk ls&lt;/code&gt; / &lt;code&gt;cdk list&lt;/code&gt; to verify if stack is created also see a list of the IDs of the stacks in your AWS CDK application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Directory structure of app will be like this – &lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;Overview of created files –&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;  .venv - The python virtual environment created in the process.&lt;/li&gt;
&lt;li&gt;cdk_demo_stack.py— A custom CDK stack construct for use in your CDK application.&lt;/li&gt;
&lt;li&gt;  tests — Contains all tests.

&lt;ul&gt;
&lt;li&gt;unit — Contains unit tests.&lt;/li&gt;
&lt;li&gt;test_cdk_demo_stack.py- Test cases for the constructs created in the cdk package. This is mainly to demonstrate how tests can be hooked up to the project.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;  app.py — The entry point for the application.&lt;/li&gt;

&lt;li&gt;  cdk.json — A configuration file for CDK that defines what executable CDK should run to generate the CDK construct tree.&lt;/li&gt;

&lt;li&gt;  README.md — The introductory README for this project.&lt;/li&gt;

&lt;li&gt;  requirements.txt/requirements-dev.txt —This file is used by pip to install all of the dependencies for your application.&lt;/li&gt;

&lt;li&gt;  source.bat — To activate the virtual environment&lt;/li&gt;

&lt;li&gt;The cdk init command also initializes the project as a Git repository, along with the .gitignore file.&lt;/li&gt;

&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;You can find a working example at &lt;a href="https://github.com/shubhampawar/CDK_Demo" rel="noopener noreferrer"&gt;cdk-demo&lt;/a&gt;,follow the &lt;a href="https://github.com/shubhampawar/CDK_Demo/blob/main/README.md" rel="noopener noreferrer"&gt; README &lt;/a&gt;for further steps.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Block diagram for cdk-demo app.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ifdbrzzjbo965rr5z4h.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ifdbrzzjbo965rr5z4h.jpg" alt="lambda-S3-Dynamo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This example uses AWS services like S3 bucket, lambda function and DynamoDB, whenever objects are dumped in s3 bucket it triggers lambda function and writes the file metadata to DynamoDB table.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Some CDK commands to interact with project.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;cdk deploy&lt;/strong&gt;: It deploys the stack using AWS CloudFormation to the configured account.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;cdk synth&lt;/strong&gt;: This generates a cdk.out file, containing a YAML-formatted template, with the resources defined in the stack converted to the equivalent AWS CloudFormation template.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;cdk diff&lt;/strong&gt;: compares your app with the deployed stack.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;cdk destroy&lt;/strong&gt;:Destroy the stack(s) name provided&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;cdk --help&lt;/strong&gt;:You can see general help about the utility and a list of the provided subcommands.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a detailed walkthrough, see the tutorial in the &lt;a href="https://docs.aws.amazon.com/cdk/v2/guide/home.html" rel="noopener noreferrer"&gt;AWS CDK Developer Guide&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Drawbacks/limitations of using AWS CDK:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Due to large number of constructs available it becomes messy to pick the right one as per requirement.&lt;/li&gt;
&lt;li&gt;  As mentioned earlier a programming language is used to create CDK Code so a standard must be maintained. Without standardization the code can become very complex and challenging to manage in future implementation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  CloudFormation vs CDK:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  CDK allows us to use loops and condition statements which reduces the code size as compared to CloudFormation.&lt;/li&gt;
&lt;li&gt;  In CDK we can use our familiar language instead of using YAML /JSON.&lt;/li&gt;
&lt;li&gt;  Reusable code can be created and tested locally in CDK.&lt;/li&gt;
&lt;li&gt;  CDK is easy to integrate with our CI/CD process
Nothing is the best, it depends on your requirement, team, project and client demand.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;blockquote&gt;
&lt;p&gt;AWS CDK is a code-first approach to defining cloud application infrastructure. In this post I described the advantages of CDK over Cloudformation and why one should use it also demonstrated how cloud applications can be created using CDK python libraries.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;center&gt;Go clean as you code 😊&lt;/center&gt;

&lt;h6&gt;
  
  
  Disclaimer: This is a personal [blog, post, statement, opinion]. The views and opinions expressed here are only those of the author and do not represent those of any organization or any individual with whom the author may be associated, professionally or personally.
&lt;/h6&gt;

</description>
      <category>aws</category>
      <category>cdk</category>
      <category>cloud</category>
      <category>python</category>
    </item>
  </channel>
</rss>
