<?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>Forem: Israel-Lopes</title>
    <description>The latest articles on Forem by Israel-Lopes (@israellopes).</description>
    <link>https://forem.com/israellopes</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%2F855493%2F6eac1cbe-c416-42a9-9cf1-24a5f113d081.jpg</url>
      <title>Forem: Israel-Lopes</title>
      <link>https://forem.com/israellopes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/israellopes"/>
    <language>en</language>
    <item>
      <title>Working with EC2 from the command line</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Thu, 11 May 2023 17:29:58 +0000</pubDate>
      <link>https://forem.com/israellopes/working-with-ec2-from-the-command-line-1c5j</link>
      <guid>https://forem.com/israellopes/working-with-ec2-from-the-command-line-1c5j</guid>
      <description>&lt;p&gt;If you landed here by parachute and don't know how to configure LocalStack to simulate an AWS environment, follow this post: &lt;a href="https://dev.to/israellopes/simulating-aws-cli-with-localstack-42kb"&gt;Simulating AWS CLI with LocalStack&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;What is EC2?&lt;/p&gt;

&lt;p&gt;EC2 (Elastic Compute Cloud) is a cloud computing service from Amazon Web Services (AWS) that allows you to create and manage virtual machine instances in the cloud. EC2 instances provide scalable and flexible computing resources, allowing you to run applications and workloads in a virtualized environment.&lt;/p&gt;

&lt;p&gt;Let's move forward now.&lt;/p&gt;

&lt;p&gt;To upload our simulated aws environment, do:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo docker run --rm -it -p 4566:4566 -p 4571:4571 localstack/localstack&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's create our first EC2 in CLI. To get started, follow the steps described in the line below:&lt;/p&gt;

&lt;p&gt;To create EC2:&lt;code&gt;aws ec2 run-instances --image-id &amp;lt;ami-id&amp;gt; --instance-type &amp;lt;instance-type&amp;gt; --key-name &amp;lt;key-pair-name&amp;gt; --security-group-ids &amp;lt;security-group-id&amp;gt; --subnet-id &amp;lt;subnet-id&amp;gt; --count &amp;lt;number-of-instances&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To run the EC2 create command, we need to provide details like IAM image type, number of instances, security group, access keys and other options.&lt;/p&gt;

&lt;p&gt;--image-id: The ID of the Amazon Machine Image (AMI) image that will be used to create the EC2 instance. The AMI is the foundation for the instance and defines the operating system and other preinstalled software.&lt;/p&gt;

&lt;p&gt;--instance-type: The type of EC2 instance you want to create. The instance type determines the compute resources, such as CPU, memory, and storage capacity, available to the instance.&lt;/p&gt;

&lt;p&gt;--key-name: The name of the key pair that you want to associate with the EC2 instance. This allows you to log into the instance using SSH (Secure Shell).&lt;/p&gt;

&lt;p&gt;--security-group-ids: The security group ID that you want to associate the EC2 instance with. The security group defines the allowed traffic rules for the instance.&lt;/p&gt;

&lt;p&gt;--subnet-id: The ID of the subnet (subnet) you want to launch the EC2 instance into. The subnet determines the network the instance will be placed on and can affect instance connectivity and availability.&lt;/p&gt;

&lt;p&gt;--count: The number of EC2 instances you want to create. Specifies how many identical instances will be created.&lt;/p&gt;

&lt;p&gt;We will then need to specify this information, let's follow below:&lt;/p&gt;

&lt;p&gt;In order to choose our image for EC2, we can use the following command to list the images available on AWS: aws ec2 describe-images, note that it will return a very large json object with details of the image architecture.&lt;/p&gt;

&lt;p&gt;Example of command output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;},
        {
            "Architecture": "x86_64",
            "CreationDate": "2023-05-11T09:57:08.000Z",
            "ImageId": "ami-fbc1c684",
            "ImageLocation": "None",
            "ImageType": "machine",
            "Public": true,
            "KernelId": "None",
            "OwnerId": "591542846629",
            "RamdiskId": "ari-1a2b3c4d",
            "State": "available",
            "BlockDeviceMappings": [
                {
                    "DeviceName": "/dev/xvda",
                    "Ebs": {
                        "DeleteOnTermination": false,
                        "SnapshotId": "snap-00e5f6c8",
                        "VolumeSize": 15,
                        "VolumeType": "standard"
                    }
                }
            ],
            "Description": "Amazon Linux AMI 2018.03.b x86_64 ECS HVM GP2",
            "Hypervisor": "xen",
            "ImageOwnerAlias": "amazon",
            "Name": "amzn-ami-2018.03.b-amazon-ecs-optimized",
            "RootDeviceName": "/dev/xvda",
            "RootDeviceType": "ebs",
            "Tags": [],
            "VirtualizationType": "hvm"
        },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have to create a new security group, because it is he who will determine entry and exit rules. We must inform the name of the group we want to create and its description:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws ec2 create-security-group --group-name MyGroupTest --description "group description"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Running the command returns something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "GroupId": "sg-0937433e1dbd16c91",
    "Tags": []
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep the GroupId as it will be useful to create the EC2. If you already have a security-group already created, you can list them as follows: aws ec2 describe-security-groups. This will list all the groups you have.&lt;/p&gt;

&lt;p&gt;We can also apply filters if you know the name of the group, in this case just use the name of the group we just created:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws ec2 describe-security-groups --filters "Name=group-name,Values=MyGroupTest"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's move on.&lt;/p&gt;

&lt;p&gt;Let's get the subnet-id, for that we can list them with the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws ec2 describe-subnets&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can apply filters if we want too:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws ec2 describe-subnets --filters "Name=subnet-id,Values=&amp;lt;subnet-id&amp;gt;"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I will use as an example the id "subnet-b8a4b5ff".&lt;/p&gt;

&lt;p&gt;Let's get instance-type, just do the command to list:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws ec2 describe-instance-types&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the return what interests us is the InstanceType field, it contains the name of the instance.&lt;/p&gt;

&lt;p&gt;Finally, let's get the key-name, which is the name of the access key (key pair) that you will use to connect to the EC2 instance. This access key is a pair of public or private keys that are used to authenticate access to the EC2 instance.&lt;/p&gt;

&lt;p&gt;If you already have one, we can list it as follows:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws ec2 describe-key-pairs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In my case I don't have it yet, so I'll have to create one, follow the step:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws ec2 create-key-pair --key-name MyKeyPairTest --output text &amp;gt; MyKeyPairTest.pem&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create a new passkey called MyKeyPairTest and save the private key in the MyKeyPairTest.pem file, just be sure to save it in a safe place.&lt;/p&gt;

&lt;p&gt;Now that we've collected all the necessary information, we can create EC2, mine looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ec2 run-instances \
  --image-id "ami-fbc1c684" \
  --instance-type "d3.2xlarge" \
  --key-name "MyKeyPairTest" \
  --security-group-ids "sg-0937433e1dbd16c91" \
  --subnet-id "subnet-b8a4b5ff" \
  --count 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now just run the command above to create our first EC2. Next step now and start our EC2 instance, just follow the example below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws ec2 start-instances --instance-ids &amp;lt;instance-id&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Standing as follows: &lt;code&gt;aws ec2 start-instances --instance-ids "i-304d1f1933d722ab6"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the successful return we want to have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "StartingInstances": [
        {
            "CurrentState": {
                "Code": 0,
                "Name": "pending"
            },
            "InstanceId": "i-304d1f1933d722ab6",
            "PreviousState": {
                "Code": 16,
                "Name": "running"
            }
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we finish our learning about EC2.&lt;/p&gt;



&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wYSQYve_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem" width="517" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Learn to use AWS IAM in command line</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Wed, 10 May 2023 20:33:05 +0000</pubDate>
      <link>https://forem.com/israellopes/learn-to-use-aws-iam-2f5i</link>
      <guid>https://forem.com/israellopes/learn-to-use-aws-iam-2f5i</guid>
      <description>&lt;p&gt;If you landed here by parachute and don't know how to configure LocalStack to simulate an AWS environment, follow this post: &lt;a href="https://dev.to/israellopes/simulating-aws-cli-with-localstack-42kb"&gt;Simulating AWS CLI with LocalStack&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is IAM?&lt;/p&gt;

&lt;p&gt;IAM (Identity and Access Management) is an AWS service that allows you to securely manage access to AWS resources and services. It provides granular control over permissions and access policies for users, groups, roles, and services within your AWS account.&lt;/p&gt;

&lt;p&gt;IAM lets you create and manage identities (users, groups, and roles) and assign&lt;br&gt;
permissions specific to those identities. Some of the main features and&lt;br&gt;
IAM features include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;User Management: You can create IAM users and provide credentials&lt;br&gt;
login for them. Each user will have a set of unique credentials&lt;br&gt;
to authenticate to the AWS account.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Groups: You can organize users into logical groups and assign permissions at the group level.&lt;br&gt;
This simplifies permission administration as you can add or remove users from&lt;br&gt;
a group and the permissions will be applied automatically.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IAM Roles: IAM roles allow you to grant temporary permissions to services and&lt;br&gt;
AWS applications. This is useful when you want to allow a service to access&lt;br&gt;
other resources in your account on your behalf, without having to share access credentials.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IAM Policies: IAM policies are JSON documents that define permissions for&lt;br&gt;
users, groups, and roles. You can create custom policies to meet requirements&lt;br&gt;
access specifics and assign those policies to identities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integration with Other Services: IAM integrates with many AWS services, allowing you to&lt;br&gt;
control access to specific features in those services. For example, you can define policies&lt;br&gt;
access to S3 buckets, EC2 instances, SQS queues and many others.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Creating user in IAM
&lt;/h2&gt;

&lt;p&gt;Now let's learn how to create our first user in IAM, just follow the command below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws iam create-user --user-name &amp;lt;username&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can now list our user: &lt;code&gt;aws iam list-users&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After the user has been created, we can now grant access to him. Here's an example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws iam attach-user-policy --user-name &amp;lt;username&amp;gt; --policy-arn arn:aws:iam::aws:policy/MyPolicy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Replace &lt;code&gt;&amp;lt;username&amp;gt;&lt;/code&gt; with the username you created and&lt;br&gt;
&lt;code&gt;arn:aws:iam::aws:policy/MyPolicy&lt;/code&gt; by the ARN (Amazon Resource Name) of the&lt;br&gt;
policy you want to associate.&lt;/p&gt;

&lt;p&gt;Below is a list of the most common policies to apply:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AmazonS3FullAccess: Grants full access to Amazon S3 storage services.

&lt;ul&gt;
&lt;li&gt;AmazonEC2FullAccess: Grants full access to Amazon EC2(Elastic Compute Cloud) services.&lt;/li&gt;
&lt;li&gt;AmazonDynamoDBFullAccess: Grants full access to Amazon DynamoDB services.&lt;/li&gt;
&lt;li&gt;AmazonRDSFullAccess: Grants full access to Amazon RDS (Relational Database Service) services.&lt;/li&gt;
&lt;li&gt;AmazonSQSFullAccess: Grants full access to Amazon SQS (Simple Queue Service) services.&lt;/li&gt;
&lt;li&gt;AmazonSNSFullAccess: Grants full access to Amazon SNS (Simple Notification Service) services.&lt;/li&gt;
&lt;li&gt;AWSLambdaFullAccess: Grants full access to AWS Lambda services.&lt;/li&gt;
&lt;li&gt;AWSReadOnlyAccess: Grants read-only access to a wide range of AWS services.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to see more policies, access the link &lt;a href="https://docs.aws.amazon.com/pt_br/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#aws-managed-policies"&gt;politicas&lt;/a&gt;&lt;br&gt;
Continuing, I want to give access to the user Luis to have access to Dynamo, in this case:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws iam attach-user-policy --user-name Luis --policy-arn arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's list the accesses of our user Luis:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws iam list-attached-user-policies --user-name Luis&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It will return the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "AttachedPolicies": [
        {
            "PolicyName": "AmazonDynamoDBFullAccess",
            "PolicyArn": "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess"
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I want to remove the access that I was given to the user, how do you do it now?&lt;br&gt;
Just follow the example, let's remove the access we just gave Luis:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws iam detach-user-policy --user-name Luis --policy-arn arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Listing the user accesses, it should return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "AttachedPolicies": []
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, we just detach &lt;strong&gt;&lt;em&gt;AmazonDynamoDBFullAccess&lt;/em&gt;&lt;/strong&gt; access to the user Luis.&lt;br&gt;
We move on now.&lt;/p&gt;

&lt;p&gt;Now let's delete the user Luis:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws iam delete-user --user-name Luis&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Finish
&lt;/h2&gt;

&lt;p&gt;We learned here how to create users, set access policies, remove them and delete users.&lt;br&gt;
There are more features that IAM can offer, but I've only presented the basics.&lt;/p&gt;



&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wYSQYve_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem" width="517" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Simulating s3 bucket on localhost</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Wed, 10 May 2023 14:06:10 +0000</pubDate>
      <link>https://forem.com/israellopes/simulating-s3-bucket-on-localhost-41fh</link>
      <guid>https://forem.com/israellopes/simulating-s3-bucket-on-localhost-41fh</guid>
      <description>&lt;p&gt;If you landed here by parachute and don't know how to configure LocalStack to simulate an AWS environment, follow this post: &lt;a href="https://dev.to/israellopes/simulating-aws-cli-with-localstack-42kb"&gt;Simulating AWS CLI with LocalStack&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What Bucket S3?&lt;/p&gt;

&lt;p&gt;Bucket S3 (Amazon Simple Storage Service) and a cloud storage container. A good one&lt;br&gt;
analogy we can do and that Bucket S3 would be a directory in a linux environment in which you&lt;br&gt;
can create the boards that would be the bucket, and within the directors the data files that&lt;br&gt;
You want to store. You don't need much attention to realize that the bucket commands are&lt;br&gt;
similar to the commands of listing and deleting on Linux.&lt;/p&gt;

&lt;p&gt;Now we follow the tutorial.&lt;/p&gt;



&lt;p&gt;Here we will learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create Bucket&lt;/li&gt;
&lt;li&gt;climb files to the bucket&lt;/li&gt;
&lt;li&gt;List Buckets and Files&lt;/li&gt;
&lt;li&gt;Delete Bucket files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To facilitate learning and is similar to the service of Amazon, let's create an alias.&lt;/p&gt;

&lt;p&gt;Inside I give your .Bashrc or another preferably, paste the follownet code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

source /home/oem/Workspace/myenv/venv/bin/activate
alias aws="aws --endpoint-url=http://localhost:4566"


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Do not forget to load the file: &lt;code&gt;source ~/.BASHRC&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this way we are overcrowding the AWS command to that of Locastack. Now in the&lt;br&gt;
do:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws --endpoint-url=http://localhost:4566 s3 mb s3://my-bucket-to-test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now it will be that way: &lt;code&gt;AWS S3 MB S3: // My-Bucket-to-Test&lt;/code&gt;, so we can create our Bucket S3.&lt;/p&gt;

&lt;p&gt;If you want, you can subscit the name "My-Bucket-To-Test" for the bucket name you want.&lt;/p&gt;

&lt;p&gt;When creating Bucket he had returned the message "Make_Bucket: My-Bucket-To-Test" on the prompt output.&lt;br&gt;
Here we will exemplify some ways to climb files to Bucket S3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bucket Upload
&lt;/h2&gt;

&lt;p&gt;Now let's are in the bucket data mass, so it will climb all files that&lt;br&gt;
are within the specified directory.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws s3 sync /home/oem/Workspace/local-stack-aws/bucket-s3/ s3://my-bucket-to-test/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When uploading to Bucket, the file will be stored with the same board structure. my&lt;br&gt;
It was as follows:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws s3 sync /home/oem/Workspace/local-stack-aws/bucket-s3/product_data.json s3://my-bucket-to-test/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you want to climb only one file, we can do it like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws s3 cp /home/oem/Workspace/local-stack-aws/bucket-s3/product_data.json s3://my-bucket-to-test/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now that we go up it let's go Baixalo:&lt;/p&gt;

&lt;h2&gt;
  
  
  Bucket download
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;aws s3 cp s3://my-bucket-to-test/product_data.json - | cat&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command assigns the Product_Data file and Cat on its exit, returning the object.&lt;/p&gt;

&lt;h2&gt;
  
  
  deleting bucket file
&lt;/h2&gt;

&lt;p&gt;First let's list our bucket:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws s3 ls s3://my-bucket-to-test/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now that we already know which one delete, let's go on:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws s3 rm s3://my-bucket-to-test/product_data.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Upon running the command it returns the following message:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;delete: s3://my-bucket-to-test/product_data.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We just said that we want to delete the Product_Data.json file of our Bucket. If we list the&lt;br&gt;
Content of our Bucket again, we will see that it no longer exists.&lt;/p&gt;



&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189" rel="noopener noreferrer"&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%2Fds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Simulating AWS CLI with LocalStack</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Tue, 09 May 2023 15:32:26 +0000</pubDate>
      <link>https://forem.com/israellopes/simulating-aws-cli-with-localstack-42kb</link>
      <guid>https://forem.com/israellopes/simulating-aws-cli-with-localstack-42kb</guid>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/israellopes/simulating-s3-bucket-on-localhost-41fh"&gt;S3 (Simple Storage Service)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/israellopes/learn-to-use-aws-iam-2f5i"&gt;IAM (Identity and Access Management)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/israellopes/working-with-ec2-from-the-command-line-1c5j"&gt;EC2 (Elastic Compute Cloud)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Lambda&lt;/li&gt;
&lt;li&gt;DynamoDB&lt;/li&gt;
&lt;li&gt;API Gateway&lt;/li&gt;
&lt;li&gt;CloudFormation&lt;/li&gt;
&lt;li&gt;CloudWatch&lt;/li&gt;
&lt;li&gt;SQS (Simple Queue Service)&lt;/li&gt;
&lt;li&gt;SNS (Simple Notification Service)&lt;/li&gt;
&lt;li&gt;Elastic Beanstalk&lt;/li&gt;
&lt;li&gt;KMS (Key Management Service)&lt;/li&gt;
&lt;li&gt;Cognito&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dependencies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS CLI&lt;/li&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;Python 2.7.x or Python 3.4&lt;/li&gt;
&lt;li&gt;python3-pip&lt;/li&gt;
&lt;li&gt;python3-venv&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To simulate the aws environment locally and very simply, first we have&lt;br&gt;
to install the &lt;strong&gt;&lt;em&gt;AWS CLI&lt;/em&gt;&lt;/strong&gt; as follows:&lt;/p&gt;

&lt;p&gt;Install the AWS CLI using a method appropriate for your operating system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-configure-quickstart-install" rel="noopener noreferrer"&gt;download aws-cli&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As my system is Linux, I will follow other steps as follows:&lt;/p&gt;

&lt;p&gt;If you don't have python on your machine, just follow&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt-get update &amp;amp;&amp;amp; sudo apt-get install python3 &amp;amp;&amp;amp; sudo apt install python3-pip&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now install AWS CLI using virtual environment.&lt;/p&gt;

&lt;p&gt;Make sure you have the python3-venv package installed by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt install python3-venv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create a new directory where you want to create the virtual environment. For example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir myenv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Enter the &lt;code&gt;cd myenv&lt;/code&gt; directory&lt;/p&gt;

&lt;p&gt;Create a virtual environment using the following command: &lt;code&gt;python3 -m venv venv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Activate the virtual environment by running the command, whenever you want to run the AWS CLI, you will need&lt;br&gt;
than run this command from the virtual environment:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;source venv/bin/activate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then just install awscli in isolation so you don't run the risk of&lt;br&gt;
dependency conflicts.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install awscli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Keep in mind that whenever you need to use the AWS CLI, you will first need to enable&lt;br&gt;
virtual environment using the &lt;code&gt;source venv/bin/activate&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;After the installation is complete, you can verify that the AWS CLI installed correctly&lt;br&gt;
typing the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws --version&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Docker in your local environment, if not already installed.&lt;/li&gt;
&lt;li&gt;Download and install LocalStack using Docker Hub. For example, you can
run the following command in the terminal:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;docker run --rm -it -p 4566:4566 -p 4571:4571 localstack/localstack&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When executing the command, if it returns this information, it means that it is roaming:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LocalStack version: 2.0.3.dev
LocalStack build date: 2023-05-06
LocalStack build git hash: 3e778577

2023-05-09T14:59:48.980 INFO --- [-functhread3] hypercorn.error : Running on https://0.0.0.0:4566 (CTRL + C to quit)
2023-05-09T14:59:48.980 INFO --- [-functhread3] hypercorn.error : Running on https://0.0.0.0:4566 (CTRL + C to quit)
Ready.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will launch the LocalStack container and expose ports 4566 and 4571,&lt;br&gt;
that are used to access the simulated services.&lt;/p&gt;

&lt;p&gt;Now you can use AWS CLI or SDKs to connect to LocalStack and interact&lt;br&gt;
with simulated services. Be sure to set the region to&lt;br&gt;
"us-east-1" and the endpoint to "&lt;a href="http://localhost:4566" rel="noopener noreferrer"&gt;http://localhost:4566&lt;/a&gt;" when using the AWS CLI or SDKs.&lt;/p&gt;

&lt;p&gt;For example, to list Amazon S3 buckets using the AWS CLI:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws --endpoint-url=http://localhost:4566 s3 ls&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will give an error because first we have to configure aws-cli on our machine. let's go to&lt;br&gt;
next step.&lt;/p&gt;

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

&lt;p&gt;Now we have to configure aws-cli before using it.&lt;/p&gt;

&lt;p&gt;Run the &lt;code&gt;aws configure&lt;/code&gt; command&lt;/p&gt;

&lt;p&gt;It will ask for the following information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS Access Key ID: Enter your AWS account access key ID.&lt;/li&gt;
&lt;li&gt;AWS Secret Access Key: Enter the secret access key corresponding to the access key
 ID provided earlier.&lt;/li&gt;
&lt;li&gt;Default region name: Enter the AWS region you want to use (for example,
 "us-east-1" or "eu-west-1").&lt;/li&gt;
&lt;li&gt;Default output format: Choose a preferred output format, such as "json", "text" or "table".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After entering all the necessary information, the credentials will be configured and&lt;br&gt;
  stored in a configuration file in the AWS CLI directory.&lt;/p&gt;

&lt;p&gt;Now you can start using LocalStack to interact with AWS services.&lt;br&gt;
For example, you can list Amazon S3 buckets using the following command:&lt;/p&gt;

&lt;p&gt;As with aws-cli: &lt;code&gt;aws s3 ls&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;With local-stack: &lt;code&gt;aws --endpoint-url=http://localhost:4566 s3 ls&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will return a list of buckets available in your AWS account.&lt;/p&gt;

&lt;p&gt;Each AWS service has its own specific commands and options that can&lt;br&gt;
be explored in the official AWS CLI documentation.&lt;/p&gt;

&lt;p&gt;Let's now create a bucket for demo usage&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws --endpoint-url=http://localhost:4566 s3 mb s3://my-bucket-to-test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you want, you can replace the name "my-bucket-to-test" with the name of the bucket you want.&lt;/p&gt;

&lt;p&gt;When creating a bucket, it will return the message "make_bucket: my-bucket-to-test" in the prompt output.&lt;/p&gt;

&lt;p&gt;Now we can list our bucket:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws --endpoint-url=http://localhost:4566 s3 ls&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;will return "2023-05-09 12:15:00 my-bucket-to-test"&lt;/p&gt;

&lt;h2&gt;
  
  
  Finish
&lt;/h2&gt;

&lt;p&gt;Remember that when running, you must first load the virtual environment and run the container:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;source venv/bin/activate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run --rm -it -p 4566:4566 -p 4571:4571 localstack/localstack&lt;/code&gt;&lt;/p&gt;



&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189" rel="noopener noreferrer"&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%2Fds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Factory Design Pattern: #2</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Mon, 08 May 2023 09:37:14 +0000</pubDate>
      <link>https://forem.com/israellopes/factory-design-pattern-2-3jci</link>
      <guid>https://forem.com/israellopes/factory-design-pattern-2-3jci</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Interface Product&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;doSomething&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ConcreteProductA implementation class&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ConcreteProductA&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;doSomething&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Doing something in ConcreteProductA"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ConcreteProductB implementation class&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ConcreteProductB&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;doSomething&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Doing something in ConcreteProductB"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Classe Factory&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductFactory&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="nf"&gt;createProduct&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equalsIgnoreCase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ConcreteProductA&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equalsIgnoreCase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"B"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ConcreteProductB&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Invalid product type: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;productA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ProductFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createProduct&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;productA&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;doSomething&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;productB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ProductFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createProduct&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"B"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;productB&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;doSomething&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have a Factory pattern that allows us to create different types of products (Product) using a factory (ProductFactory).&lt;/p&gt;

&lt;p&gt;The Product interface defines common behavior for all products. Next, we have the ConcreteProductA and ConcreteProductB classes that implement the Product interface with specific behaviors.&lt;/p&gt;

&lt;p&gt;The ProductFactory class is the factory responsible for creating product instances. It has a static method createProduct() that receives a type parameter indicating the desired product type. Based on that type, the factory instantiates and returns an object of the correct type. In the example, we have the creation of ConcreteProductA for type "A" and ConcreteProductB for type "B".&lt;/p&gt;

&lt;p&gt;Finally, in the main() method of the Main class, we demonstrate how to use the factory to create the desired products. We create a product A with ProductFactory.createProduct("A") and a product B with ProductFactory.createProduct("B"). Next, we call the doSomething() method on each product, which performs each product's specific behavior.&lt;/p&gt;

&lt;p&gt;The Factory pattern is useful when you need to create objects of different related classes, but only know the required object type at runtime. The factory abstracts object creation, allowing you to work with the common interface (Product) instead of specific implementations. This makes the code more flexible and makes it easier to add new product types in the future.&lt;/p&gt;



&lt;p&gt;____________________&lt;strong&gt;&lt;em&gt;&lt;a href="https://dev.to/israellopes/design-patterns-2n72"&gt;&amp;lt;&amp;lt; go to back&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;__________________&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wYSQYve_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem" width="517" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Singleton Design Pattern: #1</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Mon, 08 May 2023 03:19:17 +0000</pubDate>
      <link>https://forem.com/israellopes/singleton-design-pattern-1-535c</link>
      <guid>https://forem.com/israellopes/singleton-design-pattern-1-535c</guid>
      <description>&lt;p&gt;The Singleton design pattern is used to ensure that a class has only one instance for the entire program run and to provide a global point of access to that instance.&lt;/p&gt;

&lt;p&gt;There are several situations where the Singleton pattern is useful:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Management of Shared Resources: If you have a resource that needs to be shared by multiple pieces of code, such as a database connection, a log object, or a thread pool, Singleton can ensure that there is only one instance of that resource. resource and that it is globally accessible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Concurrent Access Control: Singleton can be used to control concurrent access to a shared resource. By having a single instance, you can ensure that concurrent access is coordinated and that operations are performed securely.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Access to global settings or information: If you have global information or settings that need to be accessed from different parts of the program, Singleton can provide a centralized point to access that information.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is important to keep in mind that the use of the Singleton pattern must be careful, as it can introduce coupling and make the code difficult to test. In addition, it is essential to consider your system's specific requirements and characteristics before deciding to use a Singleton.&lt;/p&gt;

&lt;p&gt;In Java, Singleton can be implemented by ensuring that the class has a private constructor, a static method to get the single instance, and a private static variable to hold that instance. In this way, the Singleton can control instance creation and provide global access to the instance.&lt;/p&gt;

&lt;p&gt;Let's see an example of its use below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// logger initialization&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;synchronized&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Lógica para registrar o log&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Log: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the "Logger" class implements the Singleton pattern to ensure that only one logger instance is created during program execution.&lt;/p&gt;

&lt;p&gt;You can use it as follows in your code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;log&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"log message"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That way you get the single instance of the logger and you can call the "log" method to record your log messages.&lt;/p&gt;

&lt;p&gt;The Singleton pattern is commonly used in scenarios where you need a single shared instance of a class across the entire application. The above "Logger" example is just an illustrative example, but you can find the Singleton pattern being used in many libraries and frameworks to provide global access to resources such as database connection pools, caches, settings, etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="err"&gt;└─&lt;/span&gt; &lt;span class="nt"&gt;Main&lt;/span&gt;
   &lt;span class="err"&gt;└─&lt;/span&gt; &lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nt"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="err"&gt;└─&lt;/span&gt; &lt;span class="nt"&gt;Logger&lt;/span&gt;
         &lt;span class="err"&gt;├─&lt;/span&gt; &lt;span class="nt"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;Logger&lt;/span&gt;
         &lt;span class="err"&gt;└─&lt;/span&gt; &lt;span class="nt"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;():&lt;/span&gt; &lt;span class="nt"&gt;Logger&lt;/span&gt;
            &lt;span class="err"&gt;└─&lt;/span&gt; &lt;span class="nt"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;Logger&lt;/span&gt;
               &lt;span class="err"&gt;└─&lt;/span&gt; &lt;span class="nt"&gt;new&lt;/span&gt; &lt;span class="nt"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have the Main class with the main method as the root node. Inside the main method, the Logger class is used.&lt;/p&gt;

&lt;p&gt;The structure of the Singleton pattern is represented by the following elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logger is the class that implements Singleton.&lt;/li&gt;
&lt;li&gt;instance is a static attribute of the Logger class that represents the single instance of the class.&lt;/li&gt;
&lt;li&gt;getInstance() is the static method of the Logger class which is responsible for returning the existing instance or creating a new one, if necessary.&lt;/li&gt;
&lt;li&gt;When the getInstance() method is called for the first time, a new instance of the Logger class is created and assigned to instance. In subsequent calls to getInstance(), the existing instance is returned.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// logger initialization&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;synchronized&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Lógica para registrar o log&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Log: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;log&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"log message"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;____________________&lt;strong&gt;&lt;em&gt;&lt;a href="https://dev.to/israellopes/design-patterns-2n72"&gt;&amp;lt;&amp;lt; go to back&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;__________________&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wYSQYve_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem" width="517" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Design Patterns</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Mon, 08 May 2023 02:55:22 +0000</pubDate>
      <link>https://forem.com/israellopes/design-patterns-2n72</link>
      <guid>https://forem.com/israellopes/design-patterns-2n72</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;



&lt;p&gt;What are design patterns?&lt;/p&gt;

&lt;p&gt;Design patterns, or design patterns, are reusable solutions to common problems that arise during software development. They are proven and tested solutions that help developers create cleaner, more flexible and maintainable code.&lt;/p&gt;

&lt;p&gt;Design patterns provide a set of guidelines and abstractions that can be applied to different situations to solve specific problems. They are not ready-to-use snippets of code, but concepts and ideas that can be implemented according to the needs of each project.&lt;/p&gt;

&lt;p&gt;There are several types of design patterns, which can be categorized into three main groups:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Creation Patterns: These patterns deal with the creation of objects, providing flexible mechanisms for creating instances of classes. Some examples include the Factory Method, Abstract Factory, Singleton, and Builder pattern.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Structural Patterns: These patterns deal with composing classes and objects to form larger structures. They help ensure that classes and objects work together efficiently. Some examples include the Adapter, Decorator, Composite, and Proxy pattern.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Behavioral Patterns: These patterns deal with the interaction between objects and the distribution of responsibilities between them. They are useful for defining how objects communicate and interact with each other. Some examples include the Observer pattern, Strategy, Template Method and Command.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below are some design patterns:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/israellopes/singleton-design-pattern-1-535c"&gt;Singleton Design Pattern&lt;/a&gt;:  This pattern is used to ensure that a class has only one instance and provides a global point of access to that instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/israellopes/factory-design-pattern-2-3jci"&gt;Factory Design Pattern&lt;/a&gt;: The Factory pattern is used to create objects without specifying the exact class of the object to be created. This provides an abstraction and flexibility in creating objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Observer Design Pattern: This pattern is used to implement the event and notification system, where an object (observer) maintains a list of other objects (observed) and is automatically notified of any state change in these objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Strategy Design Pattern: The Strategy pattern allows you to define a family of algorithms, encapsulate each one of them and make them interchangeable. This allows the algorithm to be selected at runtime based on requirements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decorator Design Pattern: The Decorator pattern is used to dynamically add functionality to an object. It allows extending the functionalities of an object without having to modify its structure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Composite Design Pattern: The Composite pattern is used to create hierarchical tree structures. It lets you treat individual objects and collections of objects uniformly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MVC Design Pattern (Model-View-Controller): The MVC pattern is used to separate business logic (Model), data presentation (View) and user interaction (Controller). This helps maintain an organized structure and makes the code easier to maintain and evolve.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DAO (Data Access Object) Design Pattern: The DAO pattern is used to separate data access logic from business code. It provides an abstraction for interacting with the database, allowing easy switching of data storage technologies without affecting the rest of the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Builder Design Pattern: Used to build complex objects step by step, allowing different representations of the same object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prototype Design Pattern: Allows the creation of new objects by cloning an existing object, avoiding the creation of several subclasses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Adapter Design Pattern: Used to allow classes with incompatible interfaces to work together through an intermediate adapter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Proxy Design Pattern: Provides a surrogate or surrogate for another object to control access to it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Facade Design Pattern: Provides a simplified interface for a complex set of subsystems, making them easier to use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Template Method Design Pattern: Defines the structure of an algorithm in a superclass, allowing subclasses to override specific algorithm steps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Command Design Pattern: Encapsulates a request as an object, allowing you to parameterize clients with different requests and queue or log requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterator Design Pattern: Provide a uniform way to access the elements of a collection, without exposing its underlying implementation.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wYSQYve_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem" width="517" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Open/Closed Principle: 2#</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Sun, 07 May 2023 13:47:23 +0000</pubDate>
      <link>https://forem.com/israellopes/openclosed-principle-2-jno</link>
      <guid>https://forem.com/israellopes/openclosed-principle-2-jno</guid>
      <description>&lt;p&gt;Open/Closed Principle: Software entities (classes, modules, functions, etc.) must be open for extension but closed for modification. This means that you should be able to extend an entity's behavior without modifying its existing source code. This promotes code reuse and modularity.&lt;/p&gt;

&lt;p&gt;Let's go to an example of the applicability of this concept.&lt;/p&gt;

&lt;p&gt;Suppose we have a system where we have different types of employees, such as RegularEmployee and Manager, and we need to calculate the salary for each of them based on different criteria. Let's start with a simple implementation without considering the Open/Closed Principle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Employee {
    private String name;
    private double salary;

    // Constructor, getters, and setters omitted for simplicity

    public double calculateSalary() {
        return salary;
    }
}

public class Manager extends Employee {
    private double bonus;

    // Constructor, getters, and setters omitted for simplicity

    @Override
    public double calculateSalary() {
        return super.calculateSalary() + bonus;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, we have the class Employee as the base and the class Manager as an extension of it. Each class has its own calculateSalary() method, where Manager adds a bonus to the base salary.&lt;/p&gt;

&lt;p&gt;However, this implementation does not follow the Open/Closed Principle because if a new type of employee emerges, we would have to modify the existing Employee class. Let's refactor the code to follow the Open/Closed Principle using interfaces and polymorphism:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Employee {
    double calculateSalary();
}

public class RegularEmployee implements Employee {
    private String name;
    private double salary;

    // Constructor, getters, and setters omitted for simplicity

    @Override
    public double calculateSalary() {
        return salary;
    }
}

public class Manager implements Employee {
    private String name;
    private double salary;
    private double bonus;

    // Constructor, getters, and setters omitted for simplicity

    @Override
    public double calculateSalary() {
        return salary + bonus;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we introduced the Employee interface that defines the calculateSalary() method. Then, we implemented the RegularEmployee and Manager classes that implement this interface.&lt;/p&gt;

&lt;p&gt;Now, if we want to add a new type of employee, such as an Intern, we can create a new class that implements the Employee interface without modifying the existing classes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Intern implements Employee {
    private String name;
    private double stipend;

    // Constructor, getters, and setters omitted for simplicity

    @Override
    public double calculateSalary() {
        return stipend;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, by following the Open/Closed Principle, we can extend the behavior of the system by adding new types of employees without modifying the existing code.&lt;/p&gt;



&lt;p&gt;___________&lt;strong&gt;&lt;em&gt;&lt;a href="https://dev.to/israellopes/single-responsibility-principle-1-ghn"&gt;&amp;lt;&amp;lt; back&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;______________&lt;strong&gt;&lt;em&gt;&lt;a href=""&gt;next page &amp;gt;&amp;gt;&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;__________&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wYSQYve_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem" width="517" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Single Responsibility Principle: #1</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Sun, 07 May 2023 00:36:28 +0000</pubDate>
      <link>https://forem.com/israellopes/single-responsibility-principle-1-ghn</link>
      <guid>https://forem.com/israellopes/single-responsibility-principle-1-ghn</guid>
      <description>&lt;p&gt;The first principle of SOLID is the Single Responsibility Principle (SRP). This principle states that each class should have only one specific responsibility, that is, a single task to perform.&lt;/p&gt;

&lt;p&gt;SRP is considered fundamental in SOLID, as it provides significant benefits in terms of code maintenance and readability. I agree that the other SOLID principles are based on this first principle. Therefore, it is essential to respect and strictly apply the SRP, as this allows for the proper implementation of the other principles.&lt;/p&gt;



&lt;p&gt;_____________________&lt;strong&gt;&lt;em&gt;&lt;a href="https://dev.to/israellopes/openclosed-principle-2-jno"&gt;next page &amp;gt;&amp;gt;&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;____________________&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wYSQYve_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem" width="517" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Microservice: Monitoring and Observability #7</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Tue, 02 May 2023 12:59:48 +0000</pubDate>
      <link>https://forem.com/israellopes/microservice-monitoring-and-observability-7-27hn</link>
      <guid>https://forem.com/israellopes/microservice-monitoring-and-observability-7-27hn</guid>
      <description>&lt;p&gt;Monitoring is the process of collecting data about system performance and availability. This includes metrics, logs, and events that can be used to identify issues and monitor the state of the system. Monitoring allows teams to identify performance and availability issues, as well as trends over time.&lt;/p&gt;

&lt;p&gt;Observability, on the other hand, is the ability to understand the behavior of the internal system based on its external signals, including logs, metrics and events. This involves collecting detailed information about the state of the system in real time, allowing operations and development teams to understand how the system is behaving and detect problems more quickly and effectively.&lt;/p&gt;

&lt;p&gt;Observability is particularly important in microservice environments, where many services are interconnected and constantly changing. Observability allows teams to monitor the state of each service individually, as well as the system as a whole, to detect issues quickly and proactively respond to them.&lt;/p&gt;

&lt;p&gt;Together, monitoring and observability are critical to ensuring the availability and performance of a microservices system, as well as allowing development and operations teams to better understand system behavior and identify areas for improvement.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Microservice: DevOps and Automation #6</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Tue, 25 Apr 2023 17:25:27 +0000</pubDate>
      <link>https://forem.com/israellopes/microservice-devops-and-automation-6-lfi</link>
      <guid>https://forem.com/israellopes/microservice-devops-and-automation-6-lfi</guid>
      <description>&lt;p&gt;DevOps is an approach that emphasizes collaboration and communication between development and operations teams to ensure faster and more reliable software delivery. This is done through process automation, continuous integration, continuous delivery and continuous system monitoring. In microservices architecture, DevOps is essential to ensure that services are delivered quickly and with high quality.&lt;/p&gt;

&lt;p&gt;Automation is another important approach in microservices architecture, which aims to reduce manual workload and increase efficiency by automating repetitive tasks. This includes automating testing, deployment, configuration management, and system monitoring. Automation is essential to handle the scalability and complexity of services in a microservices environment.&lt;/p&gt;

&lt;p&gt;Together, DevOps and Automation are critical to the success of microservices architecture. They allow development and operations teams to work together more collaboratively and efficiently, reducing errors and increasing productivity. In addition, they allow services to be delivered more quickly and reliably, ensuring customer satisfaction and the company's competitiveness.&lt;/p&gt;

&lt;p&gt;The main idea of DevOps is to establish a culture of collaboration among these teams, so that they can work together more efficiently and productively, towards a common goal: to deliver high quality software faster and more reliably.&lt;/p&gt;

&lt;p&gt;For this, the DevOps approach seeks to automate development and operations processes, including testing, deployments, monitoring and infrastructure management, allowing teams to focus more on strategic aspects of the project.&lt;/p&gt;

&lt;p&gt;DevOps also emphasizes the use of agile practices such as continuous integration (CI), continuous delivery (CD), test automation, configuration management, among others.&lt;/p&gt;

&lt;p&gt;The DevOps approach is critical in modern development environments, including microservices architecture, as it allows teams to work more collaboratively and efficiently, delivering software faster, more securely, and more reliably.&lt;/p&gt;



&lt;p&gt;___________&lt;strong&gt;&lt;em&gt;&lt;a href="https://dev.to/israellopes/microservice-independent-governance-5-58oa"&gt;&amp;lt;&amp;lt; back&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;______________&lt;strong&gt;&lt;em&gt;&lt;a href=""&gt;next page &amp;gt;&amp;gt;&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;__________&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wYSQYve_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem" width="517" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to kill unwanted ssh processes</title>
      <dc:creator>Israel-Lopes</dc:creator>
      <pubDate>Tue, 25 Apr 2023 17:22:00 +0000</pubDate>
      <link>https://forem.com/israellopes/how-to-kill-unwanted-ssh-processes-5g4m</link>
      <guid>https://forem.com/israellopes/how-to-kill-unwanted-ssh-processes-5g4m</guid>
      <description>&lt;p&gt;This command will list all connections established with the sshd process. Write down the port number of the process corresponding to the rogue connection and the ID of the process running on that port.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo netstat -tnpa | grep 'ESTABLISHED.*sshd'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can then use the &lt;code&gt;ps&lt;/code&gt; command to check the processes running on the system and find the &lt;code&gt;PID&lt;/code&gt; corresponding to the port you identified. For example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo ps aux | grep sshd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will list all running processes related to sshd. Write down the &lt;strong&gt;&lt;em&gt;PID&lt;/em&gt;&lt;/strong&gt; of the process running the port you identified.&lt;/p&gt;

&lt;p&gt;Finally, run the kill command with the &lt;strong&gt;&lt;em&gt;PID&lt;/em&gt;&lt;/strong&gt; of the process you want to kill:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo kill &amp;lt;PID&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you use creativity, you can close &lt;code&gt;http&lt;/code&gt;, &lt;code&gt;ftp&lt;/code&gt;, &lt;code&gt;telnet&lt;/code&gt; and other processes.&lt;/p&gt;



&lt;p&gt;&lt;a href="https://www.linkedin.com/in/israel-lopes-419a32189"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wYSQYve_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png" alt="Texto alternativo da imagem" width="517" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
