<?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 Ramazan Topal on Medium]]></title>
        <description><![CDATA[Stories by Ramazan Topal on Medium]]></description>
        <link>https://medium.com/@topalramazan42?source=rss-68fcc8ccd43c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Ramazan Topal on Medium</title>
            <link>https://medium.com/@topalramazan42?source=rss-68fcc8ccd43c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 13:40:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@topalramazan42/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[AWS Lambda and API Gateway using AWS CDK in Local]]></title>
            <link>https://medium.com/@topalramazan42/aws-lambda-and-api-gateway-using-aws-cdk-in-local-6892c5a57ca5?source=rss-68fcc8ccd43c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6892c5a57ca5</guid>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[localstack]]></category>
            <category><![CDATA[aws-cdk]]></category>
            <dc:creator><![CDATA[Ramazan Topal]]></dc:creator>
            <pubDate>Wed, 23 Aug 2023 05:11:06 GMT</pubDate>
            <atom:updated>2023-08-23T05:11:06.958Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will show you how to easily use AWS CDK in your local. We will use localstack to run aws services for free in our local. You can either install and use localstack on your computer or use it with the help of docker. I prefer to use it with docker.</p><p>This is the localstack website. <a href="https://docs.localstack.cloud/getting-started/installation/">Click here for download Localstack</a></p><h3><strong>Prerequisites</strong></h3><p>You will need to setup the following for this tutorial.</p><blockquote><strong>npm install -g aws-cdk</strong></blockquote><blockquote><strong>npm install -g aws-cdk-local</strong></blockquote><p>You have to verify installed correctly</p><blockquote><strong>cdklocal –version</strong></blockquote><h3>Creating a localstack with Docker</h3><p>To use localstack with docker, you must add the following commands to your docker-compose.yml file. You can skip this step if you are running Localstack on your computer</p><pre>version: &quot;3.8&quot;<br><br>services:<br>  localstack:<br>    container_name: &quot;${LOCALSTACK_DOCKER_NAME-localstack_main}&quot;<br>    image: localstack/localstack<br>    ports:<br>      - &quot;127.0.0.1:4566:4566&quot;            # LocalStack Gateway<br>      - &quot;127.0.0.1:4510-4559:4510-4559&quot;  # external services port range<br>    environment:<br>      - DEBUG=${DEBUG-}<br>      - DOCKER_HOST=unix:///var/run/docker.sock<br>    volumes:<br>      - &quot;${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack&quot;<br>      - &quot;/var/run/docker.sock:/var/run/docker.sock&quot;</pre><h3>Starting a Project</h3><p>Let’s create a new directory and a typescript sample application in it by running</p><blockquote><strong>mkdir cdklocal-typescript</strong></blockquote><blockquote><strong>cd cdklocal-typescript</strong></blockquote><blockquote><strong>cdklocal init sample-app — language typescript</strong></blockquote><h3>Checkout Localstack</h3><p>After creating our file structure, enter the url below</p><blockquote><strong>http://localhost:4566/health</strong></blockquote><p>If your localstack is not working, you will see “<strong>This site can’t be reached</strong>”</p><h3>Step 1</h3><p>We delete the contents of the class in the cdklocal-typescript-stack file in the lib folder and delete “sns, subs, sqs” module. Then, we add the following modules</p><pre>import * as apigateway from &#39;aws-cdk-lib/aws-apigateway&#39;;<br>import * as lambda from &#39;aws-cdk-lib/aws-lambda&#39;;<br>import { NodejsFunction } from &#39;aws-cdk-lib/aws-lambda-nodejs&#39;;<br>import { join } from &#39;path&#39;;</pre><h3>Step 2</h3><p>By entering the following lines of code, we create restapi and lambda function inside the Class.</p><pre>    const api = new apigateway.RestApi(this, &#39;api&#39;, {<br>      description: &#39;example api gateway&#39;,<br>      deployOptions: {<br>          stageName: &#39;dev&#39;,<br>      },<br>    });<br><br>    const nodeFunction = new NodejsFunction(this, &#39;nodeFunction&#39;, {<br>      memorySize: 1024,<br>      runtime: lambda.Runtime.NODEJS_14_X,<br>      handler: &#39;handler&#39;,<br>      entry: join(__dirname, `index.ts`),<br>    });<br><br>    const methods = api.root.addResource(&#39;hello&#39;); // This line of code add &quot;/hello&quot; url<br>    methods.addMethod(&#39;GET&#39;, new apigateway.LambdaIntegration(nodeFunction)); // This line of code satisfies the get request</pre><h3>Step 3</h3><p>We create<strong> index.ts</strong> file in our lib folder. We write a function called handler to run our lambda function in <strong>index.ts</strong> file</p><pre>export const handler = async () =&gt; {<br><br>      return {<br>          statusCode: 200,<br>          headers: { &quot;Content-Type&quot;: &quot;text/plain&quot; },<br>          body: JSON.stringify(&quot;Hello world!&quot;),<br>      };<br>};</pre><blockquote>The name we wrote against the handler key that we specified in our <strong>NodejsFunction</strong> class that we wrote in step 2 should be the same as the function name in the index.ts file. Also, the entry key in <strong>NodejsFunction</strong> must point to the index.ts file</blockquote><h3>Step 4</h3><p>In the last step, We run the following commands in order</p><blockquote><strong>cdklocal synth</strong></blockquote><blockquote><strong>cdklocal bootstrap</strong></blockquote><blockquote><strong>cdklocal deploy</strong></blockquote><p>After these commands you will see output like this:</p><blockquote>Do you wish to deploy these changes (y/n)?</blockquote><p>We press ‘y’ button</p><p>After the deploy process is finished, you will see the following output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*76wKRoTbVVid6hWM9adofQ.png" /></figure><p>We can run our function by adding /hello url to the end of the https url shown</p><h3>Conclusion</h3><p>In this article, I tried to provide information about how a lambda function works in local.I hope this example helps you for creating AWS Lambda in Local</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6892c5a57ca5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>