<?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: JNN5</title>
    <description>The latest articles on DEV Community by JNN5 (@jnn5).</description>
    <link>https://dev.to/jnn5</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%2F211209%2Facdb7302-2792-4334-a4f2-7cb7a8f7a6f4.jpeg</url>
      <title>DEV Community: JNN5</title>
      <link>https://dev.to/jnn5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jnn5"/>
    <language>en</language>
    <item>
      <title>AWS CDK tips and tricks for developers</title>
      <dc:creator>JNN5</dc:creator>
      <pubDate>Thu, 13 Feb 2025 03:01:20 +0000</pubDate>
      <link>https://dev.to/aws-builders/aws-cdk-tips-and-tricks-for-developers-2ogo</link>
      <guid>https://dev.to/aws-builders/aws-cdk-tips-and-tricks-for-developers-2ogo</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fubq9h948tv6i59f8qfzi.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fubq9h948tv6i59f8qfzi.jpeg" alt="Skateboard trick performed by a person" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The AWS CDK is for most of the people I interact with the first-time developers who get to write Infrastructure as Code in a proper programming language (sorry HCL, we were never friends).&lt;/p&gt;

&lt;p&gt;This sounds like a game changer but when you look at a lot of the examples it doesn’t really feel like programming. Instantiating classes with the same attributes you used in YAML or JSON doesn’t feel like a big gain.&lt;/p&gt;

&lt;p&gt;However, when you give it a shot there are some pretty neat things you can do.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is the AWS CDK
&lt;/h2&gt;

&lt;p&gt;The AWS CDK is a library for multiple languages and a cli to provision infrastructure on AWS and more.&lt;/p&gt;

&lt;p&gt;You use one of the major programming languages like TypeScript/Python/Java/C# etc. to define your infrastructure as instantiated classes. The CLI can turn these objects of the respective programming languages and turn them into CloudFormation templates and deploy them via the CloudFormation service.&lt;/p&gt;

&lt;p&gt;I won’t go into more detail here than this little tldr; use your favorite search engine to find out more if you feel like it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tips and tricks
&lt;/h2&gt;

&lt;p&gt;When you use the CDK out of the box, I don’t find it fun to use. Most classes have lots of parameters and some constructs depend on other constructs that then have more parameters and there is no logic flow.&lt;/p&gt;

&lt;p&gt;The classes are modelled after the AWS services rather than the way someone might approach building an app.&lt;/p&gt;

&lt;p&gt;It’s a good thing you can use proper programming languages to do something about it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trick 1: Build your own constructs with sensible defaults&lt;/strong&gt;&lt;br&gt;
Are you using lambda functions in Python with tracing? Build a PythonFunction that enables tracing with a fixed layer for lambda Powertools.&lt;/p&gt;

&lt;p&gt;Don’t want to forget to encrypt a S3 bucket and make it private? Build an EncryptedBucket construct.&lt;/p&gt;

&lt;p&gt;For any resource that is used multiple times, it’s probably a good idea to build your own construct and set some defaults.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Trick 2: Co-locate application and infrastructure code&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
You could technically put application and infrastructure code in the same file but that might not be a very good idea.&lt;/p&gt;

&lt;p&gt;What I like to do is e.g. co-locate my lambda function code with the infrastructure code for that lambda in different files but in the same folder. And by that I mean the function definition and all other components exclusive to that feature like e.g. a path in the API gateway and the DynamoDB table the lambda writes to.&lt;/p&gt;

&lt;p&gt;This way, if I’m working on a feature, I have everything that makes up the feature in one place which makes updates much easier. This leads to the nice property that my CDK stack definition is entirely made up of a collection of features that form the stack.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Tip 3: Abstract your constructs the way you would think about your architecture&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
I think this one needs a little more explaining.&lt;/p&gt;

&lt;p&gt;What I mean is that the way the AWS CDK constructs are built is by following the topology of AWS services and service boundaries. This might not be how you would want to design systems.&lt;/p&gt;

&lt;p&gt;E.g. When I write a function for a feature, I would think about the architecture from the viewpoint of the function.&lt;/p&gt;

&lt;p&gt;I would think this way. “This function is being triggered from a POST request from an API. It also writes to this database.”&lt;/p&gt;

&lt;p&gt;The AWS constructs make you declare it as follows. “This API has this path with this method and this integration to this lambda function. This table grants write access to this function.”&lt;/p&gt;

&lt;p&gt;I’ll write it down in pseudo-code (assuming you’re using Trick 1 for both my and AWS’ way)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`# my way
my_api = RestAPI(…)
my_table = EncryptedTable(…)
my_function = PythonFunction(…)

my_function.is_triggered_by_api(my_api, “/my_feature”, “POST”)
my_function.writes_to(my_table)`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`# AWS CDK way
my_api = RestAPI(…)
my_table = EncryptedTable(…)
my_function = PythonFunction(…)

my_api.add_method(“/my_feature”, “POST”, my_function)
my_table.grants_readwrite(my_function)`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you think in integration patterns or even in your domain language, you can communicate that via your constructs. The code above is just a simple example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trick 4: don’t duplicate schemas&lt;/strong&gt;&lt;br&gt;
Sometimes the boundaries in what is application code and infrastructure code are blurry. That’s not necessarily a problem as it allows developers to get things done in multiple ways. However, it can be a problem when both sides have definitions that have to match.&lt;/p&gt;

&lt;p&gt;A good example would be DynamoDB. Most developers would likely use an abstraction layer in their application code to enforce a schema to be able to work with types. But you might not want all the config to be purely in your application code (like streams, backups, billing, etc.).&lt;/p&gt;

&lt;p&gt;What you can do is take your application code schema and feed it into your infrastructure as code. But please note, that this might require reflection or some other technique to access the metadata of a class. Here is some pseudo code to elaborate what I mean&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`# Application code ORM DynamoDB table definition

@Table
class Flight
fight_id: str
takeoff: daytime
origin: str
destination: str
takeoff_index: SecondaryIndex


# Infrastructure code (in a different file)
flight_table = EncryptedTable.from_orm_class(Flight, Mode.OnDemand)`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Final Tip: CDK synth and is your friend&lt;/strong&gt;&lt;br&gt;
If you’re using IaC, chances are you’re deploying via some sort of pipeline. And likely deployment is one of the last steps. This means that anytime you get something wrong in CDK your feedback loop is slow. To speed things up, you can first check that your CDK code can be synthesized to CloudFormation by running CDK synth (either via your test runner or the CLI).&lt;/p&gt;




&lt;p&gt;I hope my tips and tricks have helped you in one way or another. If you have any other ones you’d like to share, I’d be grateful for any comments!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo by John Fornander on Unsplash&lt;/em&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>programming</category>
      <category>javascript</category>
      <category>python</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>JNN5</dc:creator>
      <pubDate>Fri, 07 Feb 2025 12:18:54 +0000</pubDate>
      <link>https://dev.to/jnn5/-2jg1</link>
      <guid>https://dev.to/jnn5/-2jg1</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/jnn5" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F211209%2Facdb7302-2792-4334-a4f2-7cb7a8f7a6f4.jpeg" alt="jnn5"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/jnn5/this-new-aws-serverless-stack-could-be-a-game-changer-1ibc" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;This New AWS Serverless Stack could be a Game-Changer&lt;/h2&gt;
      &lt;h3&gt;JNN5 ・ Jan 24&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#aws&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#docker&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#development&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#serverless&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>aws</category>
      <category>docker</category>
      <category>development</category>
      <category>serverless</category>
    </item>
    <item>
      <title>This New AWS Serverless Stack could be a Game-Changer</title>
      <dc:creator>JNN5</dc:creator>
      <pubDate>Fri, 24 Jan 2025 15:30:08 +0000</pubDate>
      <link>https://dev.to/aws-builders/this-new-aws-serverless-stack-could-be-a-game-changer-1ibc</link>
      <guid>https://dev.to/aws-builders/this-new-aws-serverless-stack-could-be-a-game-changer-1ibc</guid>
      <description>&lt;p&gt;There is a new AWS serverless stack on the rise that you should know about!&lt;/p&gt;

&lt;p&gt;AWS has been increasing its serverless service offerings and has also begun providing serverless options for existing services.&lt;/p&gt;

&lt;p&gt;Companies and individuals who are concerned about vendor lock-in have historically tried to avoid using serverless offerings from cloud providers to avoid being dependent on their unique offerings.&lt;/p&gt;

&lt;p&gt;Historically the standard AWS serverless tech stack consisted of services that are difficult to reproduce with OpenSource technology like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Amazon API Gateway&lt;/li&gt;
&lt;li&gt;AWS Lambda&lt;/li&gt;
&lt;li&gt;Amazon DynamoDB&lt;/li&gt;
&lt;li&gt;AWS Step Functions&lt;/li&gt;
&lt;li&gt;Amazon S3&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5boloy9fmws0wyu4aqk1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5boloy9fmws0wyu4aqk1.png" alt="Typlical Lambda-based AWS Serverless Architecture" width="629" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, there is a new stack that doesn’t have this problem. This new stack can simply be run anywhere and with various OpenSource technologies.&lt;/p&gt;

&lt;h2&gt;
  
  
  The New Stack
&lt;/h2&gt;

&lt;p&gt;How would a technology stack have to look like to be deployed almost anywhere? First, it would have to be open-source. Second, it would have to be considered an industry standard to be viable for most businesses. However, whether it’s processor types, hypervisors, operating systems, programming languages, frameworks, and so on, our industry has loads of varying opinions about most things and proprietary technology is a very common business model. However, there are a few that are very, wide-spread.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker for running applications&lt;/li&gt;
&lt;li&gt;SQL for databases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yes, NoSQL is on the rise, but if you look at most of the application full-stack frameworks, across languages, most of them either support or even only support SQL databases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spring/Spring Boot in the Java world&lt;/li&gt;
&lt;li&gt;.Net in C#&lt;/li&gt;
&lt;li&gt;Django in Python&lt;/li&gt;
&lt;li&gt;Rails in Ruby&lt;/li&gt;
&lt;li&gt;Laravel for PHP&lt;/li&gt;
&lt;li&gt;NestJS for JavaScript (ignoring NextJS because it doesn’t have built-in database integration)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Here is what changed&lt;/strong&gt;&lt;br&gt;
With AWS Lambda as the compute layer and DynamoDB as the database. Developers had a choice to make.&lt;/p&gt;

&lt;p&gt;Lambda was often not a great fit for existing frameworks and you typically need an additional dependency to interact with DynamoDB.&lt;/p&gt;

&lt;p&gt;So, either bend the framework to work with Lambda or stop using a framework and completely adapt to the AWS stack.&lt;/p&gt;

&lt;p&gt;Sticking to the framework could often lead to longer processing times and thereby higher costs.&lt;/p&gt;

&lt;p&gt;This has changed! Last year AWS released a very interesting new service called Amazon App Runner.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amazon App Runner&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This service is interesting because it follows a different paradigm. With the API Gateway and Lambda stack, the web and application server were moved into the cloud provider layer and the configuration moved out of the application code.&lt;/p&gt;

&lt;p&gt;All of the frameworks listed above bring application servers and expose endpoints, which were already covered by API Gateway.&lt;/p&gt;

&lt;p&gt;With App Runner, the application server and API layer are now the responsibility of the developer but App Runner covers routing, scaling, and networking.&lt;/p&gt;

&lt;p&gt;This makes frameworks first class citizens, because providing an application server that can process requests is exactly what a framework is for.&lt;/p&gt;

&lt;p&gt;Now with frameworks back in the picture, all we need is a real serverless SQL database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amazon Aurora DSQL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Currently, DSQL is still in beta, but in my opinion, it’s a game changer. Before DSQL if you wanted to run a SQL database in AWS, you had to also run a VPC, Subnets, Route Tables, Internet Gateway, Security Groups, NACLs, NAT Gateways, etc. Now while one could argue that you can set these up once via Infrastructure as Code and be done with it, I dislike this. The reason is that if I have to set up the network, then I’m suddenly responsible for network-level security.&lt;/p&gt;

&lt;p&gt;Meaning if, even by accident I change some routing or security group settings and expose my database. It's on me and suddenly I have to consider whether a team of application developers will be willing and skilled enough to run this themselves.&lt;/p&gt;

&lt;p&gt;DSQL is a truly serverless offering (unlike previous Aurora offerings) where AWS provides an endpoint for me to access the database and handles all other network and system-level security for me. Meaning that I don't have to create a VPC etc. to provision DSQL.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  The New Mental Model
&lt;/h2&gt;

&lt;p&gt;Just judging by the icons this new stack doesn’t seem all that different I admit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. You change your infra less&lt;/strong&gt;&lt;br&gt;
You have to write the IaC code for App Runner and DSQL once at the beginning of the project. When you need a new endpoint, you don’t have to touch the IaC. When you need a new table, you don’t have to touch the IaC. When you want to change your database schema, you don’t have to touch IaC. You only have to care about your infrastructure when you have to make changes to your core platform. This is great because it allows you to stay in your application context more and you don’t lose time by switching context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. You can test locally more easily&lt;/strong&gt;&lt;br&gt;
Your local testing setup is much simpler. Start Postgres and you’re done. Well almost, your connection locally is set up differently than in the cloud and you manage secrets differently, but calling a running endpoint that talks to a database doesn’t require complex config anymore.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Faster onboarding&lt;/strong&gt;&lt;br&gt;
Developers don’t need to understand much about AWS to be productive. 100 lines of IaC is digestible. Especially if you don’t need to change them that often. Several hundred lines of IaC can be daunting.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trade-offs
&lt;/h3&gt;

&lt;p&gt;Don’t trust anyone that doesn’t tell you about the trade-offs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Container image hardening&lt;/strong&gt;&lt;br&gt;
While it is possible to let AWS provide the image, I predict that most users will bring their own docker image and thereby be responsible for the security.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. API Gateway features not available&lt;/strong&gt;&lt;br&gt;
Rate limiting, API keys with usage plans, and Cognito Authorizer are probably my top 3 features that either the framework would have to provide or the developer would have to implement them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Cost currently unclear&lt;/strong&gt;&lt;br&gt;
This is probably the biggest blocker at the moment. DSQL is in public beta but currently there is no information on pricing and how AWS will charge for DSQL. This could make this stack not viable for a lot of use cases but we will just have to wait and see.&lt;/p&gt;




&lt;p&gt;I’m excited about this new serverless stack and the new mental model it comes with.&lt;/p&gt;

&lt;p&gt;I feel like it would be a great fit for developers who are annoyed by Kubernetes' complexity or the amount of IaC they have to manage.&lt;/p&gt;

&lt;p&gt;Finally, for teams trying to move away from microservices to moduliths (or modern monoliths), this is the most viable stack if you want to stay truly serverless.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The beautiful Cover Photo was taken by Kari Sheas and published on Unsplash&lt;/em&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>docker</category>
      <category>development</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
