teleren/devto huggingface dataset:
Creating Launch Template & Auto-scale group for Ec2 Creation and Automation
Tags: aws, community, ec2, automation
Published: 2023-01-09 21:20:58


Our goal is to create an auto-scale group which can automatically launch a new EC2 instance from the launch template based on the EC2 health check monitoring.
 It will kill/terminate the old EC2 instance automatically and create new one with same configuration and basic software application installations which were part of its user data script.
Auto-scale Group Creation 
 





Name your auto-scale group and create launch template for it 
 
Create New Launch template in same AWS region where you will create your auto-scale group, and your Launch template will help you to
•	Choose OS of your choice AMI (Amazon machine image).
•	Apply Essential tags to categorize your EC2 instances accordingly. 
•	Select Instance type to select best compatible type for your EC2 instance.
•	Attach Key pairs to access your machines remotely.
•	Select subnet and security group for your EC2 instance for connectivity and security 
•	Attach EBS volumes for your instance
•	Add User data script to install basic software’s and application during instance launch.
 

In auto-scale group select your created launch template and it will show the configuration of the template 
 
The Auto Scaling group must be created in the same VPC and choose the same security group which  you specified in your launch template. For the Availability Zones and subnets, choose one or more subnets in the specified VPC so you can use subnets in multiple Availability Zones for high availability
 
You can register your Amazon EC2 instances with a load balancer or choose no load balancer option if you do not want LB configurations. In case of using ELB set the amount of time until Amazon EC2 Auto Scaling checks the Elastic Load Balancing health status of an instance after it enter in the InService state.
Cloud watch metrics provide the measurements that can be useful to identify potential issue, like number of terminating instances or number of pending instances.
Enable default instance warmup, so you can choose the warm-up time for your application on EC2 instance
 

For Desired capacity, enter the initial number of instances to launch from auto-scale group and set the minimum and maximum capacity of instance you want to launch from auto-scale group. 
To automatically scale the size of the Auto Scaling group, choose the Target tracking scaling policy.
You can control whether an Auto Scaling group can terminate a particular instance when scaling in by enabling instance scale-in protection.
 
Add notifications and tags for your convenience to get notifications and categorize applications accordingly.
 
 

After review an Auto-scale group has been created 
 

Create new instance from launch template
 

After EC2 instance creation it will be taken care by its auto-scale group which is integrated with the launch template and on every potential issue the instance will be spin up and will start working as per the user data script.
The Power of Community: Ruby and Grieving
Tags: ruby, gratitude, community
Published: 2023-01-09 21:19:09

Today, I finished up Phase 3 at Flatiron School where we learned another language, Ruby, and how to connect the backend with the frontend via Sinatra. I was able to pass the code challenge and knock out a project that I am pretty proud of, thankfully. Thankfully, because during this phase, it wasn't the content that proved to be the most difficult as I initially expected but it was the unexpected death of my father. 

When I got the phone call on that Sunday morning, I felt gutted. I had a code challenge that Thursday but my motivation to get anything done immediately vanished. Writing a single line of code seemed impossible. I told my cohort the news and that I probably wouldn't be at school that week and I was contemplating whether I could even continue this program.

However, it was then I realized how special my community is at Flatiron School. The support I received from them while grieving is something that I will forever be grateful for and after a couple of days being at home and unbelievably sad, I realized I needed to be at school and around their energy to push me to get to the finish line of this phase. So for the rest of the week we all had many study sessions together to make sure that not just me but **everyone** made it to the next phase together and I am happy to say that we did. 

Although, it's going to take awhile for me to feel okay again, I have a great community around me and most importantly, I know my father would want me to continue to pursue my dreams and would be proud of the progress I have made. So this one is for you, dad.
Reflections on GNOME .Asia Summit 2022
Tags: gnome, conference, opensource
Published: 2023-01-09 20:46:17

Recently, I got an opportunity to attend GNOME Asia Summit 2022 held in Kuala Lumpur. And it was an experience that I'll never forget. 

It was my first time attending an in-person conference. I was not quite nervous and unsure of what to expect. However, from the moment I arrived at the conference, I was immediately struck by the welcoming and inclusive atmosphere.

![GNOME swags](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p5t4at8yxc6vc48gv1sl.png)

The major highlights of the conference were the diverse range of presentations and workshops. There were talks on a wide range of topics, from the technical aspects of GNOME development to getting started with Open Source Development. The speakers were experts in their respective fields, and their presentations were engaging and informative. 

![Sammy Fung Presentation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b5ixth8o7dri8xmvtzhq.png)

I also got an opportunity to meet and connect with other members of the GNOME community. I had the chance to chat with developers, designers, and advocates from different parts of the globe, and it was fascinating to hear about the different ways in which they are using and contributing to GNOME. Along with that, I also got to meet my fellow GSoCers/ friends at the event, and they made the event even more fun. 

![GNOME .Asia GSoC Group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6xf4phku7k0gtq0sjc0.png)

On the final day of the conference, I got an opportunity to give a presentation on the topic "Reworking Sync Options". You can learn more about the topic [here](https://dev.to/amankrx). 

![Aman Kumar Presentation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7uhjhyqu82bras727uoe.png)

In addition to attending the conference, I also had the opportunity to explore the vibrant city of Kuala Lumpur. With its bustling streets, colorful markets, and delicious food, Kuala Lumpur was a feast for the senses. I especially enjoyed visiting the iconic Petronas Twin Towers and KL Tower and taking a stroll through the city. Overall, I had a wonderful time exploring Kuala Lumpur and I can't wait to visit again someday.

![Petronas Towers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0l5is1mrvt44yhkduim4.png)

![Kuala Lumpur city](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4pdlnxulu0icagc06s7v.png)

I'd like to end the note by thanking the GNOME Organization for sponsoring my visit and allowing me to attend such a wonderful conference, and I hope to meet all these amazing people soon again.
Diário de bordo #3
Tags: webdev, javascript, beginners, programming
Published: 2023-01-09 20:15:47

A partir do dia 5 de janeiro eu aprendi um tópico novo em JavaScript relacionado a introdução de tratamento de erros utilizando `try` `catch` e `finally`, e é sobre este assunto que será focado o diário de hoje.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y295u4r41wiw8e15x7ri.png)

Acredito que uma das habilidades essênciais para qualquer software é realizar o tratamento de erros, sejam eles erros de sintaxe, alguma informação digitada incorretamente pelo usuário em algum lugar do sistema ou até mesmo erro em tempo de execução.


## Sintaxe Try Catch e Finally

A sintaxe do `Try Catch` é relativamente simples de aprender, ela é dívidida em dois blocos de código, onde o `Try ` é responsável por executar o código caso ocorra algum problema dentro dos comandos digitados, o Catch recebe via parametro uma função do tipo `Error` e o `Finnaly` irá executar sempre o código escrito nele independente de erros. 

```
try {
    //sua linha de código onde é informado o processo onde possívelmente ocorra algum erro
} catch(error) {
  // sua linha de código onde é responsável pelo tratamento de erro trazido pelo try
} finnaly {
   // sua linha de código onde será executado o comando independente de erros
}
```

Além disso é possível referênciar o Objeto Error das seguintes formas: 

TypeError: Onde o argumento passado para a função é de um tipo diferente da esperada.

ReferenceError: Passado quando uma variável ou função é inválida ou inexistente. 

SyntaxError: Como o próprio nome diz, ela é passada quando ocorre um erro de sintaxe na interpretação do código.

RangeError: É lançado quando um valor é passado como argumento em uma função que não está em conjunto com os valores permitidos. 

URIError: Ocorre quando há algum erro no tratamento da URI.
Intro to React Context
Tags: react, hooks, beginners
Published: 2023-01-09 20:05:04

React Context is a React hook that allows you to manage state globally. [Per W3Schools](https://www.w3schools.com/react/react_usecontext.asp), "[React Context] can be used together with the useState Hook to share state between deeply nested components more easily than with useState alone." Instead of "prop drilling" (passing state via props through your component hierarchy), you can use Context to pass state through children components.

## Getting Started: Creating Context
To get started, import `createContext` (and `useState`):
```
import { createContext, useState } from "react"
```

Then initialize `createContext`:
```
const FoodContext = createContext()
```

Finally, wrap the components you want to have access to the context in the Context Provider with the value of your state:
```
function App() {
    const [food, setFood] = useState({
        name: "Pho",
        cuisine: "Vietnamese",
        portion: 1
    })
    
    return (
        <FoodContext.Provider value={food}>
            <ChildComponent />
        </FoodContext.Provider>
    )
}
```

## Using Context
Now that you've created your Context, you'll need to use the `useContext` hook in your child component(s) to access it. Start by importing `useContext`:
```
import { useContext } from "react"
```

Finally, you can use useContext throughout your child component(s)!
```
function ChildComponent() {
    const food = useContext(FoodContext)
    
    return (
        <h1>{My Favorite is: ${food.name}}</h1>
    )
}
```

## Updating State in Child Components
In addition to passing state as the value in your Context Provider, you can also include the setter function to update state from child components. For example:
```
<FoodContext.Provider value={{ food, setFood }}>
    <ChildComponent />
</FoodContext.Provider>
```

Now, in your child component, you have access to the state and the setter function:
```
function ChildComponent() {
    const { food, setFood } = useContext(FoodContext)
    
    if (food.name === "Pho") {
        setFood((previousFood) => {
            return {
                ...previousFood,
                name: "Bánh mì"
            }
        })
    }
    
    return (
        <h1>{My Favorite is: ${food.name}}</h1>
    )
}
```

## Conclusion
React Context allows your child components to easily access data from a parent. Depending on how deep your component hierarchy is, Context can be a simpler way to pass data through your component tree than passing data as props.
Dependency relation in AWS CDK
Tags: dependency, aws, awscdk, cdk
Published: 2023-10-19 07:05:29

---
title: Dependency relation in AWS CDK
published: true
date: 2023-01-09 19:45:42 UTC
tags: #dependency #AWS #awscdk #CDK
canonical_url: https://blog.mikaeels.com/dependency-relation-in-aws-cdk
---

![AWS CDK](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9x1xwxkup9d04x4imnjo.jpeg)



Sometimes when using the AWS Cloud Development Kit (CDK), the correct order for provisioning resources may not be automatically inferred. For instance, if you have an Amazon Elastic Compute Cloud (EC2), it will depend on your Virtual Private Cloud (VPC) resource.

Another example will be if you have a MySQL Relational Database Service (RDS) instance and an EC2 instance. In this case, you may want the EC2 instance to be created after the database so that you can run initialization code, and create tables, if necessary.

To specify dependencies in CDK, you can use the `addDependency()` method on the resource `node` and include the `DependsOn` attribute to indicate that the creation of resource **A** should follow that of resource **B**.

Here is an example of how you might use the `addDependency()` method in the AWS CDK to specify a dependency between two resources:

```
const vpc = new ec2.Vpc(this, 'my-vpc', {
  cidr: '10.0.0.0/16',
});

const db = new rds.DatabaseInstance(this, 'my-db', {
  engine: rds.DatabaseInstanceEngine.MYSQL,
  vpc,
});

const ec2 = new ec2.Instance(this, 'my-ec2', {
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.T2,                     
  ec2.InstanceSize.MICRO),
  machineImage: new ec2.AmazonLinuxImage(),
  vpc,
});

// Add a dependency between the EC2 instance and the RDS database
ec2.node.addDependency(db);

```

This will ensure that the `RDS` the database is created before the `EC2` instance, allowing you to run any necessary initialization code on the `EC2` instance after the database is available.
Everyone Struggles - WSL
Tags: beginners, typescript, programming, opensource
Published: 2023-01-09 19:42:09

I have always known Linux distros like **Ubuntu** to be opensource and that it is more efficient and reliable for software development.

Since **Windows** is widespread, software developers employ virtual machines like Oracle virtual box to run other operating system on Windows.

This has been my default way of doing things. Running a VM on Windows always consumed lots of CPU power and RAM because I was running the full Ubuntu distro.

This practice continued until I Joined the Outreachy space. I began researching better and faster ways of doing things and this led to my discovery of WSL - Windows Subsystem for Linux.

I was skeptical at first because I was going to lose some GUI functionality that the full Ubuntu distro offered. I was also unsure of the performance and as such I reached out to my colleagues who provided better insight that led to my decision in using WSL.

Prior to using WSL, my local machine would freeze after sometime of running Ubuntu in the VM but now it doesn't do that anymore. My projects are CPU intensive but I am able to cope by minimizing the RAM and CPU usage by running **WSL**

It was a struggle but I rose above it because I was able to ask for help.
Introduction to cloud computing
Tags: aws, cloud, cloudcomputing, devops
Published: 2023-01-09 19:36:37

**Introduction**
Hi, I am shanu agrawal from the past few weeks, I started exploring AWS, so I decided to document what I learn. Today, I'll discuss cloud technology with you.

Every new technology solves a problem before we know what is cloud computing. we need to understand why cloud computing is, How did the software development process happen before cloud computing and how did it become easy after the cloud technology

**How did It start?**
Suppose, we are in 2006-07, I asked you a simple question. what certain activities and tasks you would perform to run any application? Think for a minute...

I tell you, you got to

1. - Create and setup server,
2. - Install the operating system,
3. - Install and setup database,
4. - Manage software patches and hardware updates,
5. - Manage capacity and scaling
6. - High Availability through load-balancing and so on...
7. - plus have to write code.

Think for a while, about how difficult it was for small and mediums sized companies and individuals too to create any application because this server infrastructure and the computing power have their costs.

To solve this major problem, cloud computing comes into the picture. A game changer for the whole software industry. They made us possible to build applications at the fraction of the cost that leverages these advancements in the computing space. Their motive is to enhance productivity, so that company completely focuses on writing clean and efficient code, rest cloud is there to handle from building infrastructures to the availability of your product worldwide. You just need to upload the code to the cloud provider.

**Other Features of Cloud Service**
In the Market, there are 3 types of cloud Computing, Each type has its distinct range of services.

Saas - Software as a service
Paas - Platform as a service.
Iaas - Infrastructure as a service.

**Cloud Providers**
There are several cloud infrastructure providers, and the top three players are AWS, Microsoft Azure & Google cloud services.

AWS is the oldest and by far the largest. Currently, holds about a third of the cloud computing market and offers more than 200 discrete products and services. AWS also has the largest geographic reach of the major providers, AWS also offers plenty of incentives and tools to lure you into the cloud.

As AWS is in huge demand, I'll try to cover more features and usage of it, In the Coming blogs, I'll discuss AWS Lambda, API Gateway, Step functions, and much more.

Thanks for reading, Happy Coding :)
Thank you dev.to!
Tags: meta, watercooler, community
Published: 2023-01-09 19:13:13


Hey dev.to community,

I just wanted to say a big thank you to the dev.to team for the gift you sent me over the holidays. I just received it in the mail. The card is awesome (and there is a shiny sticker)!

![dev.to gift](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/anvvfg7qdmlnc1jbjk0d.jpg)

![zoom on the card](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wt1d8txnck2hq0xnaczz.jpg)

It was such a cool surprise and it really made my day. I'm so appreciative of the recognition for my contributions over the past year (top author 2022, wow).

**Thank you dev.to** for the effort and attention that you put towards the authors and contributors, and for all the nice additions you gave us last year. It's clear that this is a platform that cares about and supports its community, and I'm grateful to be a part of it.

I also wanted to **thank the entire dev.to community** and especially my followers for the great vibe, all the kind words in comments and reactions, and for fostering such a positive and supportive online space.

I didn't have any specific goals when I first started writing on dev.to, and I never expected to post more than a couple of articles. But with your support and encouragement, I've found the motivation to keep going. Thank you for helping me stay inspired!

Take care, keep learning and sharing, and happy coding!
Jenkins for running scripts!
Tags: automation, scripting, jenkins, perl
Published: 2023-01-09 19:09:37

I have over 30 scripts that are used to pull data and push data between different services. Its critical to know when they fail. Sure you could do this with cron but then I looked around and saw that Jenkins could run scripts and have a console output log, and email me on fails.

After you have set up jenkins and set up the email settings.

1. Create a freestyle project
     1. Build Triggers -> set your time so it runs whenever you want.
     2. Build Steps -> Add Build Step -> Execute Shell
`perl <my/path/to/script.pl`
     3. Post Build -> Email Notification and make sure Send Email for every unstable build is checked.

This will get your scripts running and have email alerts on failed scripts. Its super helpful and its nice to have a decent web ui to automate and organize all these jobs I have to run.

---

If anyone has a better system / suggestion please let me know, I like what I have but I have been looking for something not so heavy on Java.
144. Binary Tree Preorder Traversal
Tags: beginners, programming, tutorial, leetcode
Published: 2023-01-09 19:01:50

## Intuition
This is a standard tree traversal algorithm where we visit the root, then left node and then right node.
* Inorder traversal - left root right
* Postorder traversal - left right root

## Approach
* Using Stack : 
1. Push the root node to the stack.
2. Until the stack is not empty, first store the top element of the stack to our result.
3. Preorder traversal is root -> left -> right.
Since we use stack which is LIFO, we first push the right node to the stack, then push the left node to the stack.

* Using recursion : 
1. Check whether the node is null and this is the base condition for recursion.
2. Store the node value to our result.
3. Visit the left node.
4. Visit the right node.

## Complexity
- Time complexity:
We are going through all the nodes of the tree. If the tree have n number of nodes, then time complexity will be O(n).

- Space complexity:
We store maximum number of element = height of the tree to the stack. So space complexity = O(H) where H = height of tree

## Code
```java
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> preorderTraversal(TreeNode root) {
        // preorder - root left right
        // inorder - left root right
        // postorder - left right root
        List<Integer> result = new ArrayList<>();
        if (root == null) {
            return result;
        }
        byUsingStack(root, result);
        byUsingRecursion(root, result);
        return result;
    }

    private void byUsingStack(TreeNode node, List<Integer> result) {
        Stack<TreeNode> stack = new Stack<>();
        stack.push(node);
        while (!stack.isEmpty()) {
            TreeNode top = stack.pop();
            result.add(top.val);
            if (top.right != null) {
                stack.push(top.right);
            }
            if (top.left != null) {
                stack.push(top.left);
            }
        }
    }

    private void byUsingRecursion(TreeNode node, List<Integer> result) {
        if (node == null) {
            return;
        }
        result.add(node.val);
        byUsingRecursion(node.left, result);
        byUsingRecursion(node.right, result);
    }
}
```