<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ernesto Lopez</title>
    <description>The latest articles on DEV Community by Ernesto Lopez (@aernesto24).</description>
    <link>https://dev.to/aernesto24</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%2F460305%2Fb9fec136-3aa4-420e-b1a0-23704e5d4255.png</url>
      <title>DEV Community: Ernesto Lopez</title>
      <link>https://dev.to/aernesto24</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aernesto24"/>
    <language>en</language>
    <item>
      <title>List networking information configured during Google Cloud Foundation Setup</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Sun, 17 Nov 2024 15:47:34 +0000</pubDate>
      <link>https://dev.to/aernesto24/list-networking-information-configured-during-google-cloud-foundation-setup-25h</link>
      <guid>https://dev.to/aernesto24/list-networking-information-configured-during-google-cloud-foundation-setup-25h</guid>
      <description>&lt;h2&gt;
  
  
  Gogle Cloud Foundation Setup
&lt;/h2&gt;

&lt;p&gt;A foundation setup in Google Cloud is essentially &lt;strong&gt;the base layer of your cloud&lt;/strong&gt; environment. It's the core infrastructure that supports all your applications and workloads. Think of it as the foundation of a house - it needs to be strong, secure, and well-planned to support everything built on top of it.&lt;/p&gt;

&lt;p&gt;During the Foundation setup, the relevant activities configured are:&lt;br&gt;
Here's a breakdown of what it entails:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Organizational Structure:&lt;/strong&gt; How you organize your cloud resources using folders, projects, and the organization itself. This ensures proper resource management and access control.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Identity and Access Management (IAM):&lt;/strong&gt; Controlling who has access to what resources and what they can do with them. This is crucial for security and compliance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Networking:&lt;/strong&gt; Setting up your Virtual Private Cloud (VPC) network, subnets, firewalls, and connectivity to on-premises or other cloud environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Implementing security measures like firewalls, organization policies, and data encryption to protect your data and applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automation:&lt;/strong&gt; Automating tasks like resource provisioning, configuration management, and deployments to increase efficiency and reduce errors.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These steps could be performed using the console throught the Google Cloud setup service &lt;/p&gt;

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

&lt;p&gt;Another option is to use terraform to deploy the environments, for that we can use several options like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Exporting terraform code from Google Cloud setup &lt;/li&gt;
&lt;li&gt;Using Google Cloud &lt;a href="https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/tree/master/fast" rel="noopener noreferrer"&gt;Fast Fabric&lt;/a&gt; terraform code.&lt;/li&gt;
&lt;li&gt;Creating your own code tailored to your needs &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Networking in Foundation setup
&lt;/h3&gt;

&lt;p&gt;One of the critical steps during the foundation setup is the networking section, here you will need to decide the network achitecture and other aspects like &lt;strong&gt;shared vpcs&lt;/strong&gt;, &lt;strong&gt;connection to onprem&lt;/strong&gt;, &lt;strong&gt;firewall rules&lt;/strong&gt;, etc.&lt;/p&gt;

&lt;p&gt;During foundation creation, the main activities on this phase are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Shared Virtual Private Cloud (VPC) networks
&lt;/li&gt;
&lt;li&gt;Configure connectivity between the external provider and Google Cloud.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[OPTIONAL]&lt;/strong&gt; configure Dyrectory Sync
&lt;/li&gt;
&lt;li&gt;Set up a path for external egress traffic (Cloud NAT or Public Access)
&lt;/li&gt;
&lt;li&gt;Implement network security controls (Firewall rules)
&lt;/li&gt;
&lt;li&gt;Choose an ingress traffic option (example Load Balancer)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's the importance of networking in your Google Cloud foundation setup in ten bullet points:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Connectivity:&lt;/strong&gt; Enables communication between resources, on-premises networks, and the internet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Allows for firewalls, security tools, and network segmentation to protect resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Isolation:&lt;/strong&gt; Creates boundaries between resources to limit the impact of security breaches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; Optimizes routing for fast and efficient data flow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; Supports future growth and resource expansion.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility:&lt;/strong&gt; Adapts to changing application needs and hybrid/multi-cloud environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global Reach:&lt;/strong&gt; Connects resources across different regions for low-latency access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficiency:&lt;/strong&gt; Streamlines traffic flow and reduces data transfer costs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Control:&lt;/strong&gt; Provides granular control over network traffic and access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automation:&lt;/strong&gt; Enables automated network management for reduced operational overhead.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;However there are times where you will not create the network from scratch because this was created by another person in a previous time  or maybe the implementation documentation is not in place, for those cases the following list of commands could be very helpful:&lt;/p&gt;
&lt;h4&gt;
  
  
  List VPCs in a project
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;gcloud compute networks list --project=&amp;lt;projectName&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command displays a list of all the Virtual Private Cloud (VPC) networks within a specific Google Cloud project.&lt;/p&gt;

&lt;p&gt;You replace &lt;strong&gt;&lt;/strong&gt; with the actual ID of your project to see its networks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; if you want to see the results in table format use &lt;br&gt;
&lt;code&gt;gcloud config set accessibility/screen_reader false&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  List VPCs in a project
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;gcloud compute networks subnets list  --network=&amp;lt;vpcName&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command lists all the subnets that belong to the VPC network. You would replace &lt;strong&gt;&lt;/strong&gt; with the actual name of the VPC network you're interested in. This allows you to explore the subnet structure of different networks in your project.&lt;/p&gt;
&lt;h4&gt;
  
  
  List Firewall Rules associates with a VPC
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; FIrewall rules listing return too much information, in this case we are going to filter the data and only obtain information that appears in the following table:&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud compute firewall-rules list --format="table(
        name,
        network,
        direction,
        priority,
        sourceRanges.list():label=SRC_RANGES,
        destinationRanges.list():label=DEST_RANGES,
        allowed[].map().firewall_rule().list():label=ALLOW,
        denied[].map().firewall_rule().list():label=DENY,
        sourceTags.list():label=SRC_TAGS,
        sourceServiceAccounts.list():label=SRC_SVC_ACCT,
        targetTags.list():label=TARGET_TAGS,
        targetServiceAccounts.list():label=TARGET_SVC_ACCT,
        disabled
    )"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command lists all firewall rules in your Google Cloud project and displays them in a table format with specific details. Let's break down what each part means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;gcloud compute firewall-rules list:&lt;/strong&gt; This is the basic command to list all firewall rules.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--format="table(...)"&lt;/code&gt;: This part specifies that the output should be displayed in a table format. Inside the parentheses, you define the columns you want to see.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;name&lt;/code&gt;: The name of the firewall rule.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;network&lt;/code&gt;: The network the rule applies to (e.g., "default" network).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;direction&lt;/code&gt;: Whether the rule applies to incoming traffic (INGRESS) or outgoing traffic (EGRESS).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;priority&lt;/code&gt;: The priority of the rule (lower numbers mean higher priority).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sourceRanges.list():label=SRC_RANGES&lt;/code&gt;: The source IP address ranges that the rule applies to.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;destinationRanges.list():label=DEST_RANGES&lt;/code&gt;: The destination IP address ranges that the rule applies to.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;allowed[].map().firewall_rule().list():label=ALLOW&lt;/code&gt;: The allowed protocols and ports (e.g., tcp:80, udp:53).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;denied[].map().firewall_rule().list():label=DENY&lt;/code&gt;: The denied protocols and ports.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sourceTags.list():label=SRC_TAGS&lt;/code&gt;: Source tags that the rule applies to (tags are labels on VMs).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sourceServiceAccounts.list():label=SRC_SVC_ACCT&lt;/code&gt; : Source service accounts that the rule applies to.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;targetTags.list():label=TARGET_TAGS&lt;/code&gt;: Target tags that the rule applies to.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;targetServiceAccounts.list():label=TARGET_SVC_ACCT&lt;/code&gt;: Target service accounts that the rule applies to.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;disabled&lt;/code&gt; : Whether the rule is currently disabled (true or false).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Essentially, this command gives you a comprehensive overview of your firewall rules in a structured table, making it easier to understand your network security configuration.&lt;/p&gt;

&lt;h4&gt;
  
  
  List VPN Information
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;gcloud compute vpn-tunnels list --filter="region:( us-central1 europe-west1 )"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command lists all VPN tunnels in your Google Cloud project that are located in either the us-central1 or europe-west1&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gcloud beta compute vpn-tunnels describe &amp;lt;vpnTunnelName&amp;gt; --region &amp;lt;region&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command provides detailed information about a specific VPN tunnel named in &lt;strong&gt;&lt;/strong&gt; located in the region of your Google Cloud project. It uses the gcloud beta compute vpn-tunnels describe command, which fetches configuration details, status information, and other relevant data about the specified tunnel. This is useful for troubleshooting, monitoring, or simply getting a comprehensive view of a particular VPN tunnel's settings and operational state.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gcloud beta compute vpn-gateways describe &amp;lt;vpnGatewayName&amp;gt; --region &amp;lt;region&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The command retrieves detailed information about a specific VPN gateway in your Google Cloud project, including its &lt;strong&gt;configuration&lt;/strong&gt;, &lt;strong&gt;status&lt;/strong&gt;, and other relevant data. You need to replace &lt;strong&gt;&lt;/strong&gt; with the actual name of your gateway and &lt;strong&gt;&lt;/strong&gt; with its location (e.g., us-central1). This is useful for troubleshooting connection issues, monitoring the gateway's health, and verifying its configuration.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gcloud compute routers describe &amp;lt;vpc-router&amp;gt; --region &amp;lt;region&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command retrieves detailed information about a Cloud Router in your Google Cloud project. You replace &lt;strong&gt;&lt;/strong&gt; with the name of the router and &lt;strong&gt;&lt;/strong&gt; with its Google Cloud region (e.g., us-central1). This provides insights into the router's configuration, BGP settings, interfaces, and operational status, which is useful for network management, troubleshooting connectivity issues, and verifying that the router is operating as expected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SUMMARY&lt;/strong&gt; With these commands you can generate tables with relevant information to know an specific environment or to put it into a delivery summary documentation, however this is way more easier if you use infrastructure as code to generate your infrastructure, that way your code is your own documentation.&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>landingzone</category>
      <category>networking</category>
      <category>cli</category>
    </item>
    <item>
      <title>3 Aspects to consider when using Google Cloud Serverless VPC Access</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Mon, 26 Dec 2022 22:12:19 +0000</pubDate>
      <link>https://dev.to/aernesto24/3-aspects-to-consider-when-using-google-cloud-serverless-vpc-access-3f2k</link>
      <guid>https://dev.to/aernesto24/3-aspects-to-consider-when-using-google-cloud-serverless-vpc-access-3f2k</guid>
      <description>&lt;p&gt;&lt;strong&gt;Serverless VPC Access&lt;/strong&gt; is a service inside Google Cloud that allows to connect serverless services to your Virtual private cloud.By default, services like Cloud Functions, Cloud Run, App Engine uses external endpoints that allow other services to reach to them. In case that you want to keep connection to these services only accessible to other instances inside a &lt;a href="https://cloud.google.com/vpc" rel="noopener noreferrer"&gt;VPC&lt;/a&gt; and to use private IPs and private DNS you need to use &lt;a href="https://cloud.google.com/vpc/docs/serverless-vpc-access" rel="noopener noreferrer"&gt;Serverless VPC Access&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are good documentation about how to use it, even for &lt;a href="https://cloud.google.com/vpc/docs/shared-vpc" rel="noopener noreferrer"&gt;Shared VPC&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Run&lt;/strong&gt;: &lt;a href="https://cloud.google.com/run/docs/configuring/connecting-shared-vpc" rel="noopener noreferrer"&gt;Connecting to a Shared VPC network&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Functions&lt;/strong&gt;: &lt;a href="https://cloud.google.com/functions/docs/networking/connecting-shared-vpc" rel="noopener noreferrer"&gt;Connecting to a Shared VPC network&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;App Engine&lt;/strong&gt;: &lt;a href="https://cloud.google.com/appengine/docs/standard/python3/connecting-shared-vpc" rel="noopener noreferrer"&gt;Connecting to a Shared VPC network&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the next sections, I will focus on 3 networking aspects that we should consider when using Serverless VPC Access:&lt;/p&gt;




&lt;h2&gt;
  
  
  IP Addressing
&lt;/h2&gt;

&lt;p&gt;In reality, Serverless VPC Access consist of an access conector that is created using VM instances (On December 2022 there are only 3 types: &lt;code&gt;f1-micro&lt;/code&gt;, &lt;code&gt;e2-micro&lt;/code&gt;,&lt;code&gt;e2-standard-4&lt;/code&gt;). The Instance selection is based on the network Throughput you require and the "cluster" can be minimum &lt;strong&gt;2&lt;/strong&gt; instances and maximum &lt;strong&gt;10&lt;/strong&gt; instances, in fact this is the default configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: These instances are not listed inside GCE instance API. You can test it by running &lt;code&gt;gcloud compute instances list&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It is recommended to set a custom number for maximum and then increased based on your needs because &lt;strong&gt;connectors don't scale down automatically or manually&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When configuring the Serverless VPC connector you need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Associate the connector to a VPC network, one connector to one VPC. The VPC can be in the same project or in another project.&lt;/li&gt;
&lt;li&gt;Create an IP Range, more on this point Next.This also mean that the Connector is associated with a Region, it is not Global.&lt;/li&gt;
&lt;li&gt;Define Escaling configuration (min and max) and instance Type. All instances are the same type, you cannot mix &lt;code&gt;f1-micro&lt;/code&gt; with e2-micro` inside the same connector.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let's get to the point, &lt;strong&gt;IP Addressing&lt;/strong&gt;. You must configure &lt;strong&gt;/28&lt;/strong&gt; IP CIDR Range, unused inside the same VPC (example 192.168.1.0/28). This is important, &lt;strong&gt;the iP Addressing range must not overlap with any existing Subnet range inside the VPC&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;You cannot use a different mask other than /28, and the reason behind it rest in the maximum configuration, if tyou recall you can have up to 10 instances, a /28 subnet mask will give you 16 IP Address, &lt;a href="https://cloud.google.com/vpc/docs/subnets#reserved_ip_addresses_in_every_subnet" rel="noopener noreferrer"&gt;Google reserve 4&lt;/a&gt; for their use, you have 12 IP Addresses that you can use. &lt;/p&gt;

&lt;p&gt;If you try to use a different ip range it will show an error:&lt;/p&gt;

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

&lt;p&gt;As you may have noticed, it evens pre-populate the /28 for you and it is grayed out, an indicator that is not configurable. &lt;/p&gt;

&lt;p&gt;Another detail, this IP Range will not appear inside the VPC's Subnet ranges, In the following example you may see &lt;strong&gt;4 subnets&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6w0xmp9f4hkpn8x38lh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6w0xmp9f4hkpn8x38lh.png" alt="Image description" width="800" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But when you enter inside the VPC Subnets details it appears only 2:&lt;/p&gt;

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

&lt;p&gt;Even if you try to list the subnets using &lt;code&gt;gcloud compute networks subnets list&lt;/code&gt; you will not be able to see them. you can use the following CLI command to retrieve the vpc-access subnets:&lt;br&gt;
&lt;code&gt;gcloud compute networks vpc-access connectors list --region=us-central1 --filter='NETWORK=vpc-demo-1'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The best option is to create a Subnet and assign that subnet during connector creation&lt;/strong&gt;, that way you will be able to track the subnets related to VPC Access:&lt;/p&gt;

&lt;p&gt;Note: Remember that you need to use /28 otherwise it will not recognize the subnet during Serverless VPC Connector&lt;/p&gt;

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

&lt;p&gt;Now when we create the connector:&lt;/p&gt;

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

&lt;p&gt;Look the difference between a connector using an Existing Subnet and one using CUSTOM IP.&lt;/p&gt;

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

&lt;p&gt;From the security section, you can use IP Assigned with Firewall Rules, additionally &lt;strong&gt;serverless VPC Access Connector&lt;/strong&gt; is created with two tags that you can use for firewall rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Universal network tag&lt;/strong&gt;: &lt;code&gt;vpc-connector&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unique network tag&lt;/strong&gt;: &lt;code&gt;vpc-connector-REGION-CONNECTOR_NAME&lt;/code&gt;. Example: &lt;code&gt;vpc-connector-us-central1-vpc-access-test-connector&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  CLOUD NAT
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;TL;TR&lt;/strong&gt;&lt;br&gt;
When you use &lt;strong&gt;Serverless VPC Access with Cloud NAT&lt;/strong&gt;, the port allocation for Cloud NAT is for Serverless VPC connector instances and no for functions or container, so if you have 2 Instances in the connector and one public IP Addresses the port allocation is between the instances in the region, incluiding the &lt;strong&gt;2 instances&lt;/strong&gt; in the connector.&lt;/p&gt;

&lt;p&gt;Consider this architecture:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvymf6o9hbbxaajehxtp3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvymf6o9hbbxaajehxtp3.png" alt="Image description" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Where we have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One&lt;/strong&gt; Cloud Run function that curl an external URL &lt;code&gt;http://ifconfig.me&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;One Serverless VPC Connector with Custom IP in &lt;code&gt;us-central1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Cloud NAT in &lt;code&gt;us-central1&lt;/code&gt; with one public ip address and &lt;strong&gt;dynamic port allocation&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to replicate this example, create a cloud run service with a code simialr to this:&lt;br&gt;
`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello_world&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://ifconfig.me&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello {}!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;debug&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0.0.0.0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PORT&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deploy the cloud run service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;gcloud run deploy curler-private-egress \
  --vpc-connector projects/vpn-site1/locations/us-central1/connectors/run-external-traffic \
  --vpc-egress=all-traffic \
  --platform managed \
  --region us-central1 \
  --no-allow-unauthenticated \
  --max-instances=10
```



Serverless VPC Connector:

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



And Cloud NAT config similar to this

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

After triggering several time the service, by calling the **cloud run service's DNS** from an instance inside the same VPC. The instance's service account require the `cloud run invoker` role.

You can use something like this:



````console
for i in {1..100}
  do
&lt;/span&gt;&lt;span class="gp"&gt;  curl -H "Authorization: Bearer $&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;gcloud auth print-identity-token&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;" https://curler-private-egress-61zgbtvvvv-uc.a.run.app
&lt;/span&gt;&lt;span class="go"&gt;done
```




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

And inside the logs you will see:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jdjz409yyc8jzmeei8gz.png)
Note that the `src_ip` in Cloud NAT's logs (the private IP that make the request to external resources) are the ones from the **Serverless Connector**.

&lt;/span&gt;&lt;span class="gp"&gt;&amp;gt;&lt;/span&gt;VMs with an external IP address can have 64,000 TCP, 64,000 UDP, and 64,000 ICMP-query sessions &lt;span class="o"&gt;(&lt;/span&gt;ping&lt;span class="o"&gt;)&lt;/span&gt; simultaneously &lt;span class="k"&gt;if &lt;/span&gt;they have enough compute/memory resources. For Cloud NAT, this limit is reduced to a total of 64,000 connections per VM &lt;span class="k"&gt;for &lt;/span&gt;all supported protocols combined.
&lt;span class="go"&gt;
************************************************************
&lt;/span&gt;&lt;span class="gp"&gt;#&lt;/span&gt;&lt;span class="c"&gt;#Deleting the VPC&lt;/span&gt;
&lt;span class="go"&gt;
Let's supose that you try to delete the VPC that have a Serverless VPC Connector:

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

If there is a subnetwork being used by Serverless VPC Connector, you will NOT be able to delete the VPC, receiving the next error message:
&lt;/span&gt;&lt;span class="gp"&gt;&amp;gt;&lt;/span&gt;The deletion of the network failed. Error: The subnetwork resource &lt;span class="s1"&gt;'projects/vpc-test1/regions/us-central1/subnetworks/vpc-access-test-serverless-us-central1'&lt;/span&gt; is already being used by &lt;span class="s1"&gt;'projects/vpc-test1/zones/us-central1-b/instances/aet-uscentral1-vpc--access--test--connector-506w'&lt;/span&gt;
&lt;span class="go"&gt;
First you will need to delete the connector:

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

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

But, What happens with a VPC where i create a Connector using Custom IP insteado of an existing subnet?

Spoilert alert!!!! you will receive the same error:
&lt;/span&gt;&lt;span class="gp"&gt;&amp;gt;&lt;/span&gt;The deletion of the network failed. Error: Operation &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;delete] failed with message &lt;span class="s2"&gt;"The network resource 'projects/vpc-test1/global/networks/red-test-vpc' is already being used by 'projects/vpc-test1/global/firewalls/aet-uscentral1-rb--vpc--connector--test245-sssss'"&lt;/span&gt;
&lt;span class="go"&gt;
The recommendation is, make sure you review resources using your VPC prior attempting to delete it.

You can use **[Cloud Asset Inventory](https://cloud.google.com/asset-inventory/docs/overview)** service and filter by `compute.Network` and move to Resource TAB, and you will obtain a list of resources that live inside the VPC.








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

&lt;/div&gt;

</description>
      <category>googlecloud</category>
      <category>devops</category>
      <category>networking</category>
    </item>
    <item>
      <title>My recommendations to approve Google Associate Cloud Engineer and Professional Cloud Architect certifications in 60 days</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Fri, 13 May 2022 20:16:00 +0000</pubDate>
      <link>https://dev.to/aernesto24/my-path-to-approve-two-google-cloud-certifications-in-60-days-5725</link>
      <guid>https://dev.to/aernesto24/my-path-to-approve-two-google-cloud-certifications-in-60-days-5725</guid>
      <description>&lt;p&gt;As a brief introduction, i will let you the links to the certifications so you can start thinking about the first recommendation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Google Cloud Certified &lt;a href="https://cloud.google.com/certification/cloud-engineer" rel="noopener noreferrer"&gt;&lt;strong&gt;Associate Cloud Engineer&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftkabeqnre0wiefgv1nxl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftkabeqnre0wiefgv1nxl.png" alt="ACE-BADGE" width="800" height="741"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Google Cloud Certified &lt;a href="https://cloud.google.com/certification/cloud-architect" rel="noopener noreferrer"&gt;&lt;strong&gt;Professional Cloud Architect&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwsqt6g3kapvdt225z174.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwsqt6g3kapvdt225z174.png" alt="PCA-BABDGE" width="800" height="671"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Base on the previous list, my first advice is to find two certifications that are closely related, this way you can use the study from the first one as a base for the second one.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;NOTE&lt;/strong&gt;: This is my personal experience, i came from working with AWS and Oracle cloud from several years so i have strong knowledge in cloud computing. Experience is important but it is not all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ANOTHER NOTE&lt;/strong&gt;: Google Cloud manage some services in a different way so from time to time you need to forget about waht things are done on AWS or another cloud provider.&lt;/p&gt;




&lt;h2&gt;
  
  
  Start point &amp;gt; Base knowledge
&lt;/h2&gt;

&lt;p&gt;Here i have two recommendations, if you came from AWS for example of from Azure, on Pluralsight there are two courses that provide a translation to Google Cloud services:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://app.pluralsight.com/library/courses/google-cloud-aws-professionals/table-of-contents" rel="noopener noreferrer"&gt;Google Cloud Fundamentals for AWS Professionals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://app.pluralsight.com/library/courses/google-cloud-azure-windows-professionals/table-of-contents" rel="noopener noreferrer"&gt;Google Cloud Fundamentals for Azure Professionals&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These trainings allow you to map the services that you know with the services on Google Cloud, and to identify the important differences. &lt;strong&gt;In my case&lt;/strong&gt; was very useful for IAM and Storage area.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;NEXT&lt;/strong&gt;, we well keep ourself on Pluralsight, there are &lt;em&gt;Certifications Paths&lt;/em&gt; created by Google Cloud, so let me emphasize this, the certifications trainings are created by Google itself. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;For Associate Cloud Engineer&lt;/strong&gt; start with this path:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://app.pluralsight.com/paths/certificate/cloud-architecture-with-google-cloud" rel="noopener noreferrer"&gt;Google Cloud Certified Professional Cloud Engineer&lt;/a&gt;. The path is around &lt;em&gt;17 hours&lt;/em&gt; of video content and maybe another &lt;em&gt;12 hours&lt;/em&gt; for labs but it will give you a solid ground for knowledge.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;For Professional Cloud Architect&lt;/strong&gt; start with this path:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://app.pluralsight.com/paths/certificate/cloud-engineering-with-google-cloud" rel="noopener noreferrer"&gt;Google Cloud Certified Associate Cloud Architect&lt;/a&gt;. The path is around *27 hours&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;of video content and maybe another &lt;em&gt;20 hours&lt;/em&gt; for labs. The advantage with this one is taht it has some trainings from the previous path so you do not need need to view the courses again.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  So, if both path share most of the trainings why should a present two different certifications?
&lt;/h4&gt;

&lt;p&gt;Well, the short answer is yo do not need to present both, but it will give you a different set of skills. &lt;/p&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;For example under &lt;strong&gt;ACE&lt;/strong&gt; beside services and base architecture usage you are tested on hands on activities, specially on CLI, this knowledge is base for cloud administration and for other certifications.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;While on &lt;strong&gt;PCA&lt;/strong&gt; you are tested on architecting solutions for specific business needs, and less on CLI commandos or process to configure managed services. &lt;strong&gt;Example:&lt;/strong&gt; you will be tested about when to use certain load balancer but not how to configure it.&lt;br&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  OKOK got it, but why Pluralsight?
&lt;/h4&gt;

&lt;p&gt;Well for trainings yu have several options: Pluralsight, Coursera, A Cloud Guru, etc. Why i choose pluralsight? because the trainings are created by google itself and are updated once a year and in some cases twice a year, so you will have updated content for your certifications.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Extra recommenation for base knowledge.
&lt;/h4&gt;

&lt;p&gt;After i passed the &lt;strong&gt;ACE exam&lt;/strong&gt; a beautiful book was released&lt;br&gt;
&lt;a href="https://www.amazon.com/Visualizing-Google-Cloud-Illustrated-References/dp/1119816327/ref=sr_1_1?crid=2ZIB6E87MLHM6&amp;amp;keywords=Visualizing+Google+Cloud%3A+101+Illustrated+References+for+Cloud+Engineers+and+Architects&amp;amp;qid=1652464324&amp;amp;sprefix=visualizing+google+cloud+101+illustrated+references+for+cloud+engineers+and+architects%2Caps%2C111&amp;amp;sr=8-1" rel="noopener noreferrer"&gt;Visualizing Google Cloud: 101 Illustrated References for Cloud Engineers and Architects&lt;/a&gt; from &lt;strong&gt;Priyanka Vergadia&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;The most amazing from this book is that is separated by vertical&lt;/strong&gt;, example storage, compute, etc and provides you with a graphical way of mapping Google Cloud services and then a brief explanation of each one, &lt;strong&gt;ending each chapter with some use cases for those services previously explained&lt;/strong&gt;. &lt;br&gt;
&lt;em&gt;I use this book from time to time to prepare some presentation for a customer so it is recommended.&lt;/em&gt;&lt;/p&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Practice, Practice, Practice - Read, Read, Read
&lt;/h2&gt;

&lt;p&gt;You need to get in touch with the Google cloud console, Google provide you with a &lt;a href="https://cloud.google.com/free" rel="noopener noreferrer"&gt;300 USD free credits&lt;/a&gt; for new customer, so you can create your account and start testing and playing.&lt;/p&gt;

&lt;p&gt;Also, you can create an account for &lt;a href="https://www.cloudskillsboost.google/" rel="noopener noreferrer"&gt;CloudSkillboost&lt;/a&gt; (Qwiklabs)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can find hundred of guided labs, &lt;strong&gt;with durations from 30 min to 2 hours&lt;/strong&gt; ,some are free and some will cost you a certain amount of credits.&lt;/li&gt;
&lt;li&gt;Labs are grouped on path so you can go specifically to the &lt;strong&gt;ACE&lt;/strong&gt; or &lt;strong&gt;PCA&lt;/strong&gt; paths.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Infrastructure is created&lt;/strong&gt; for you at the begining each lab so you do not need to worry about spending your Google Cloud credits. And it is destroyed when you end the lab, &lt;strong&gt;so do not store anything on it.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Specially for &lt;strong&gt;ACE&lt;/strong&gt; test you need to practice, get confident configuring each services and read the documentation from the Console, sometimes it provides you with informatiion that is asked during the test&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjldhkws2rvy9gcx6psq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjldhkws2rvy9gcx6psq.png" alt="console documentation" width="616" height="309"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;This is an example of documentation from the console when creating a cloud run service&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Ok practice a lot, got it, but why do i need to read?
&lt;/h3&gt;

&lt;p&gt;Read is one of the activities that i enjoy the most, but is is a personal choice, &lt;strong&gt;the fact is that i study from the official learning guides&lt;/strong&gt; and it helped me a lot to understand certain examples and architectures, so let see what are the guides for each exam:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For Associate Cloud Engineer&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.amazon.com/Google-Cloud-Certified-Associate-Engineer/dp/1119564417/ref=sr_1_1?__mk_es_MX=%C3%85M%C3%85%C5%BD%C3%95%C3%91&amp;amp;crid=118NIP35JPC6L&amp;amp;keywords=Official+Google+Cloud+Certified+Associate+Cloud+Engineer+Study+Guide&amp;amp;qid=1652467802&amp;amp;s=books&amp;amp;sprefix=official+google+cloud+certified+associate+cloud+engineer+study+guide%2Cstripbooks%2C106&amp;amp;sr=1-1" rel="noopener noreferrer"&gt;Official Google Cloud Certified Associate Cloud Engineer Study Guide&lt;/a&gt;from &lt;a href="https://www.linkedin.com/in/dansullivanpdx/" rel="noopener noreferrer"&gt;Dan Sullivan&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;This Guide is from 2019, it hasn't been updated &lt;strong&gt;BUT&lt;/strong&gt; as my best understanding it does not need to be updated, you can find example configuration from CLI that are the same right now.&lt;/li&gt;
&lt;li&gt;The book is around &lt;strong&gt;500 pages&lt;/strong&gt; long, but &lt;strong&gt;like 20 to 25% of the book&lt;/strong&gt; are images from cloud console or diagrams.&lt;/li&gt;
&lt;li&gt;It is for sure that you find variations between images and current Console configuration but you can take advantage of this book from the explanations and practice questions.&lt;/li&gt;
&lt;li&gt;Language is easy to follow and the explanations are concise and direct to the point. &lt;/li&gt;
&lt;li&gt;The books is &lt;strong&gt;dividied in chapters by services&lt;/strong&gt;, and it excels on showing specific use cases for each service and guide you to select the best option for a requirement.

&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;For Professional Cloud Architect&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.amazon.com.mx/gp/product/1119871050/ref=ppx_yo_dt_b_asin_title_o03_s00?ie=UTF8&amp;amp;psc=1" rel="noopener noreferrer"&gt;Google Cloud Certified Professional Cloud Architect Study Guide&lt;/a&gt;from &lt;a href="https://www.linkedin.com/in/dansullivanpdx/" rel="noopener noreferrer"&gt;Dan Sullivan&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IMPORTANT&lt;/strong&gt; there are 2 guides on Amazon, the one from 2019 and the new one from April 2022. Buy the new one, Professional Architect exam includes &lt;strong&gt;4 study cases and the 2022 version&lt;/strong&gt; has the new study cases so this will help you with the current version of the test.&lt;/li&gt;
&lt;li&gt;This book is around 300 pages long, and only like 2% are graphics so this is heavy reading.&lt;/li&gt;
&lt;li&gt;Explanations are simple to understand and include real scenarios use cases.&lt;/li&gt;
&lt;li&gt;The mos useful aspects of this Guide are:

&lt;ul&gt;
&lt;li&gt;There are &lt;strong&gt;2 chapters&lt;/strong&gt; where Dan explain the use cases and posible analysis to understand requirements, very useful for the test.&lt;/li&gt;
&lt;li&gt;There is a chapter for &lt;strong&gt;Software development process&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;There is a chapter for Compliance certifications, so if you have experience with compliance you can skip it.&lt;/li&gt;
&lt;li&gt;Review question has some use case similar to the ones from the test.&lt;/li&gt;
&lt;li&gt;There is little to nothing about configuration or commands son if you want more on that review the &lt;strong&gt;ACE Guide&lt;/strong&gt;.
&lt;em&gt;This guide is base on the current exam so you can use this book as **a blueprint&lt;/em&gt;* and look other sources to dive deeper on the concepts presented here.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  2 weeks previous the test date
&lt;/h3&gt;

&lt;p&gt;The aspect exposed previously were for learning the basics, getting involved and confident with services and configuration and acquiring deep knowledg for each one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In my Experience&lt;/strong&gt;, the week or ween and a half previous to the exam, you need a different type of course. You need a course that &lt;strong&gt;has all included and also that provides you with some tips to remember during the test&lt;/strong&gt;.&lt;br&gt;
Looking for this type of trainings i found an exceptional course for each exam:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For Associate Cloud Engineer&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.udemy.com/share/104aBM3@u2YPPL1ijZnpZ3PeERj5ISb_0CeFM4U5JiYFowMU8phEIdvtYKsM6AiaeDOgICAo/" rel="noopener noreferrer"&gt;GCP Associate Cloud Engineer - Google Cloud Certification&lt;/a&gt; from &lt;a href="https://courses.in28minutes.com/" rel="noopener noreferrer"&gt;In28Minutes&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;This training is about 17 hours, but includes all the subjects needed for the exam.&lt;/li&gt;
&lt;li&gt;There are several lectures with command example and also include code examples so you can test it yourself.&lt;/li&gt;
&lt;li&gt;The training does not just focus on the exam, it also provide examples and configuration for a standard day to day job.&lt;/li&gt;
&lt;li&gt;Under this training i found tips that were not available on the official guide and under the Pluralsight courses.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe78g1avts5nqb4vjzp6i.png" alt="In28Minutes ACE" width="464" height="558"&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For Professional Cloud Architect&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.udemy.com/share/104qEo3@iykjlzcfecGwgCy9qJ6R9w8_0jJrhexLvQKLYncBL8o_plm4xkqQvoDtwRjaEqAg/" rel="noopener noreferrer"&gt;GCP Professional Cloud Architect: Google Cloud Certification&lt;/a&gt; from &lt;a href="https://courses.in28minutes.com/" rel="noopener noreferrer"&gt;In28Minutes&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The training is about 20 hours of content, it includes some videos from the &lt;strong&gt;ACE&lt;/strong&gt; course but the majority are &lt;strong&gt;PCA&lt;/strong&gt; focused.&lt;/li&gt;
&lt;li&gt;There is a chapter to review the new case studies, this is gold.&lt;/li&gt;
&lt;li&gt;On the Exam there are questions about SREs, Agile, DevOps cuture. And this training has videos for all of that.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdq56wq2feu05xmssyd8n.png" alt="In28minutes PCA" width="478" height="564"&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  During the Test
&lt;/h3&gt;

&lt;p&gt;I am going to talk a little about my experience with each exam.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; i am not going to talk about the process to login remote proctored or in place, just my experience during the test.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;For Associate Cloud Engineer&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;50 Questions in 2 hours, i finished in 1 hour and 15 min.&lt;/li&gt;
&lt;li&gt;Questions were more related to configuration oiptions, selecting a product over another, CLI commands.&lt;/li&gt;
&lt;li&gt;On my test there were heavy focus on storage and database options, so take special care about BigQuery configuration or databases selection.&lt;/li&gt;
&lt;li&gt;This test will not ask anything as specific as : tell me with compute instance type have 16 VCPUs or what is the limit of pods in a cluster, but you need to know tha limitations because it can affect the service selection for the answer.&lt;/li&gt;
&lt;li&gt;The questions are short, the explanation of the cases or requirements are simple. take special attention of the requirements and the things that the client does not want under the configuration.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;For Professional Cloud Architect&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;50 Questions in 2 hours, i completed the test in 1 hour and 51 minutes.&lt;/li&gt;
&lt;li&gt;Know the use cases before presenting, this will help you to prevent spending time reading the use cases. &lt;a href="https://cloud.google.com/certification/guides/professional-cloud-architect/" rel="noopener noreferrer"&gt;study cases here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;In my test there were 2 cases from the 4 available, and around 14 questions about cases.&lt;/li&gt;
&lt;li&gt;Questions in this exam are long, because they are explaining the business and technical requirements so be prepare to read a lot. By the end of the test i felt tired and needed to re read questions.&lt;/li&gt;
&lt;li&gt;Take special care of business requirements, technical requirements can be met with different products but business requirements are the one that define the correct answer. Remember ARCHITECT test is more focus on Business.&lt;/li&gt;
&lt;li&gt;You can access the study cases at any time during the test.&lt;/li&gt;
&lt;li&gt;try not to loose time on questions, if you spend more than 5 min in a question it is better to move to the next one.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  What else?
&lt;/h3&gt;

&lt;p&gt;Well other recommendations are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can read some tips and key notes from this &lt;a href="https://github.com/aernesto24/certifications-keynotes" rel="noopener noreferrer"&gt;repo&lt;/a&gt;(WIP)&lt;/li&gt;
&lt;li&gt;Visit the &lt;a href="https://cloud.google.com/architecture" rel="noopener noreferrer"&gt;Google cloud reference architecture Center&lt;/a&gt; : here you can find architecture examples, blueprints, and use cases,&lt;/li&gt;
&lt;li&gt;Read the blogs from medium, specially the ones written in Google Cloud community, somo of this provide real world scenarios and configurations --&amp;gt; &lt;a href="https://medium.com/google-cloud" rel="noopener noreferrer"&gt;HERE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Commit to study everyday, this will help to retain concepts and easier the process. the week before the test i spent around 4 to 5 hours a day studying so be prepare for this marathon.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>googlecloud</category>
      <category>certification</category>
      <category>career</category>
    </item>
    <item>
      <title>Learning GO (Golang): First steps and the mighty "Hello world"</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Tue, 01 Feb 2022 21:26:28 +0000</pubDate>
      <link>https://dev.to/aernesto24/learning-go-golang-first-steps-and-the-mighty-hello-world-oam</link>
      <guid>https://dev.to/aernesto24/learning-go-golang-first-steps-and-the-mighty-hello-world-oam</guid>
      <description>&lt;p&gt;These blog post are going to be me showing how i am learning &lt;strong&gt;Go&lt;/strong&gt;, you are going to be part of my travel and i will take advantage of all of you by making sure i am learning the concepts. SO let's start this Journey.&lt;/p&gt;




&lt;h2&gt;
  
  
  A little background
&lt;/h2&gt;

&lt;p&gt;I &lt;strong&gt;always&lt;/strong&gt; like to start by understanding why something is used for, what are the possibilities with certain technologies or languages and who is using it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's get started by writing some of the main characteristics of the Go language:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Open Source&lt;/strong&gt; programming language.&lt;/li&gt;
&lt;li&gt;It was created at &lt;strong&gt;Google&lt;/strong&gt; in 2007, anounced in 2009 and was released publicly in 2012 (So it has been out there for a while). And was designed thinking in merge the strenghts of &lt;strong&gt;C&lt;/strong&gt; language and the easy syntax of languages like python.&lt;/li&gt;
&lt;li&gt;It is a compiled, statically typed language. These two aspects represents a really good learning opportunity as i come from python.&lt;/li&gt;
&lt;li&gt;Rich &lt;a href="https://golang.org/pkg/" rel="noopener noreferrer"&gt;package library&lt;/a&gt;. Well, it is less rich than python's library but it is growing.&lt;/li&gt;
&lt;li&gt;It was designed thinking on performance, it will use your resources as efficiently as possible, specially &lt;strong&gt;CPU&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Provides Goroutines and channels to deal with concurrency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kubernetes&lt;/strong&gt; is written in GO. As a DevOps engineer this is really interesting. &lt;/li&gt;
&lt;li&gt;Go generates binaries for your applications with all the dependencies built in, avoiding the need to install runtimes, and also this make GO multiplatform, so code developed on linux can run on MAC or WIndows only by having GO installed on those systems.&lt;/li&gt;
&lt;li&gt;It is in the &lt;strong&gt;TOP 10&lt;/strong&gt; of the most loved languages in &lt;a href="https://insights.stackoverflow.com/survey/2021" rel="noopener noreferrer"&gt;stackoverflow&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  All these features look nice, but then i moved to another question, what is GO used for??
&lt;/h2&gt;

&lt;h3&gt;
  
  
  According to &lt;a href="https://go.dev/solutions/#use-cases" rel="noopener noreferrer"&gt;GO official website&lt;/a&gt; you can use Go for:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc2finqk8k3w2rqjafivy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc2finqk8k3w2rqjafivy.png" alt="Use-cases-for-go" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Source&lt;/em&gt;:&lt;a href="https://go.dev/solutions/#use-cases" rel="noopener noreferrer"&gt;GO Use cases&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What jumps to my attention was the cloud aspect, so digging a little further i have found reference about using &lt;strong&gt;GO&lt;/strong&gt; for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Networking automation&lt;/li&gt;
&lt;li&gt;CLoud scripts&lt;/li&gt;
&lt;li&gt;MAchine learning, and several engineer has been using GO for Data Science.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But related to this aspect, the most interesting part is that &lt;strong&gt;GO&lt;/strong&gt; really excels on infrastructure stuff, this is why &lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;, &lt;a href="https://kubernetes.io/" rel="noopener noreferrer"&gt;Kubernetes&lt;/a&gt; and &lt;a href="https://prometheus.io/" rel="noopener noreferrer"&gt;Prometheus&lt;/a&gt; are build on GO.&lt;/p&gt;


&lt;h2&gt;
  
  
  Really cool features and use cases, but who is using it?
&lt;/h2&gt;

&lt;p&gt;This was my third question, i wanted to know if learning Go will help me on my current job or if it will helpful in the future.&lt;/p&gt;

&lt;p&gt;So let's travel again to the oficial GO website and look who is using the language.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9s9imnrc9c9ppbzg49z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9s9imnrc9c9ppbzg49z.png" alt="CLients-go" width="800" height="449"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Source&lt;/em&gt;:&lt;a href="https://go.dev/" rel="noopener noreferrer"&gt;Who is using GO&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Very interesting, Google was the creator so it should be using it, and the rest of companies using it are important ones. These companies using this language let us know how important it is, and taking a look in pages like LinkedIn you can also notice an increment on GO developers requirements.&lt;/p&gt;

&lt;p&gt;Now, i was convinced, this was a good technology to learn, so i started this journey.&lt;/p&gt;


&lt;h2&gt;
  
  
  First of all, install Go
&lt;/h2&gt;

&lt;p&gt;I have always think that infrastructure and architectura subjects can be learn by studying, but coding requires practicing. THe first step is to install GO, get in touch with the process and lear where are the bins stored and how the language works.&lt;/p&gt;

&lt;p&gt;As i saw in several sites, it is recommended to use &lt;strong&gt;GO on Linux&lt;/strong&gt;, it is not mandatory just a recommendation. I will be installing GO 1.17 (*At the date of this post, version 1.18 i think was already release, but this 1.17 is stable).&lt;/p&gt;

&lt;p&gt;For the OS, i am using Using &lt;strong&gt;Ubuntu 20.04&lt;/strong&gt; on a laptop and for coding i am using &lt;strong&gt;Visual Studio Code&lt;/strong&gt;, i have more experience using this software and the GO plugin is really good.&lt;/p&gt;

&lt;p&gt;Let's get started, i follow the steps on the &lt;a href="https://go.dev/dl/" rel="noopener noreferrer"&gt;official documentation for Linux installation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the software was downloaded i follow this steps:&lt;br&gt;
&lt;a href="https://go.dev/doc/install" rel="noopener noreferrer"&gt;GO Installation guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; you can download your installer anywhere you want, but you should decompress it on the route &lt;code&gt;/usr/local/bin&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;** Note ** using this steps yo should log out and them login back so the &lt;code&gt;.profile&lt;/code&gt; get the changes on the path.&lt;/p&gt;

&lt;p&gt;You can test the installation was correct by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(base) ernestol@ubuntu:~/go$ go version
go version go1.17.6 linux/amd64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Now you need to configure your environment for developement
&lt;/h3&gt;

&lt;p&gt;After installing go i created 3 directories under &lt;code&gt;home/go&lt;/code&gt; (&lt;em&gt;you should also create the go folder&lt;/em&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;go
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;go/
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;bin pkg src
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls
&lt;/span&gt;bin  pkg  src
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may ask, why this folders, well i used them for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;bin&lt;/strong&gt; is where all executables that we create are going to be stored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pkg&lt;/strong&gt; is where dependencies packages will be stored&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;src&lt;/strong&gt; is where we will store our code &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After this steps we can go to the powerful &lt;strong&gt;"Hello world!!"&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  THe Mighty "Hello world!!"
&lt;/h2&gt;

&lt;p&gt;I started by creating a directory inside &lt;code&gt;home/go/src&lt;/code&gt; with my hello world project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;go/
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls
&lt;/span&gt;bin  pkg  src
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;src/
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;basic_golang
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;basic_golang/
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src/basic_golang&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;
/home/ernestol/go/src/basic_golang
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are going to start coding, it is recommended to name the file &lt;strong&gt;main.go&lt;/strong&gt; but i think it is not mandatory. The file it should have an extension .go (This is MANDATORY).&lt;/p&gt;

&lt;p&gt;After creating this file we are going to add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"HELLO WORLD!!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What looks nice to me that you do not event have to write the import statement, when you save the file, go automatically add you the import because it recognize that you are using the &lt;strong&gt;fmt&lt;/strong&gt; and that you need to import it, this was really nice.&lt;/p&gt;

&lt;p&gt;to execute it, you must first compile it (using &lt;code&gt;go build&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src/basic_golang&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls
&lt;/span&gt;src
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src/basic_golang&lt;span class="nv"&gt;$ &lt;/span&gt;go build src/main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this step you will notice a new file named &lt;strong&gt;main&lt;/strong&gt; this is the one you will execute&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src/basic_golang&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-al&lt;/span&gt; 
total 1740
drwxrwxr-x 3 ernestol ernestol    4096 feb  1 15:16 &lt;span class="nb"&gt;.&lt;/span&gt;
drwxrwxr-x 3 ernestol ernestol    4096 feb  1 15:10 ..
&lt;span class="nt"&gt;-rwxrwxr-x&lt;/span&gt; 1 ernestol ernestol 1766430 feb  1 15:16 main
drwxrwxr-x 2 ernestol ernestol    4096 feb  1 15:13 src
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src/basic_golang&lt;span class="nv"&gt;$ &lt;/span&gt;


&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src/basic_golang&lt;span class="nv"&gt;$ &lt;/span&gt;./main 
HELLO WORLD!!
&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src/basic_golang&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another thing that looks very interesting to me was that if you write something that is not along with the syntax best practices, the VS Code plugin will let you know and go will not compile, let see this in action.&lt;/p&gt;

&lt;p&gt;Let's say we want the code to appear nice by adding { in a new line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"HELLO WORLD!!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;VS Code will put it as an error:&lt;/p&gt;

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

&lt;p&gt;AN if you try to compile the code you will receive the following errors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src/basic_golang&lt;span class="nv"&gt;$ &lt;/span&gt;go run src/main.go 
&lt;span class="c"&gt;# command-line-arguments&lt;/span&gt;
src/main.go:5:6: missing &lt;span class="k"&gt;function &lt;/span&gt;body
src/main.go:6:1: syntax error: unexpected semicolon or newline before &lt;span class="o"&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SO you better pay attention to those errors,&lt;/p&gt;

&lt;p&gt;Also you can notice that even if you add new lines &lt;strong&gt;Go&lt;/strong&gt; will rearrange the code for you, &lt;strong&gt;a nice feature if you ask me!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;FInally, if you want to run the code as a test without the need to compile it you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt; ernestol@ubuntu:~/go/src/basic_golang&lt;span class="nv"&gt;$ &lt;/span&gt;go run src/main.go 
HELLO WORLD!!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; take into account that this option provide less performance but it is a good way to test a change quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;THIS WAS MY FIRST BABY STEP&lt;/strong&gt;&lt;br&gt;
I will be posting more of this to document my journey on this language.&lt;/p&gt;




&lt;h2&gt;
  
  
  Sources:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go &lt;a href="https://go.dev/" rel="noopener noreferrer"&gt;Official website&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GO &lt;a href="https://go.dev/blog/" rel="noopener noreferrer"&gt;Blog&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A cloud Guru&lt;/strong&gt;: &lt;a href="https://acloudguru.com/blog/engineering/what-is-go-an-intro-to-googles-go-programming-language-aka-golang" rel="noopener noreferrer"&gt;What is Go? An intro to Google’s Go programming language (aka Golang)&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PLatzi training&lt;/strong&gt;: &lt;a href="https://platzi.com/cursos/programacion-golang/" rel="noopener noreferrer"&gt;Curso Básico de Programación en Go&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TechWorld with Nana&lt;/strong&gt; &lt;a href="https://www.youtube.com/watch?v=yyUHQIec83I" rel="noopener noreferrer"&gt;Golang Tutorial for Beginners | Full Go Course&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@thisisdasc/seven-golang-features-you-must-know-about-944485d413fe" rel="noopener noreferrer"&gt;Seven Golang Features you must know about&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>googlecloud</category>
      <category>beginners</category>
      <category>programming</category>
      <category>go</category>
    </item>
    <item>
      <title>Automating log downloads from MongoDB Atlas</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Fri, 28 Jan 2022 19:37:35 +0000</pubDate>
      <link>https://dev.to/aernesto24/automating-log-downloads-from-mongodb-atlas-56op</link>
      <guid>https://dev.to/aernesto24/automating-log-downloads-from-mongodb-atlas-56op</guid>
      <description>&lt;p&gt;MongoDB Atlas can provide 2 types of logs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Process Logs&lt;/strong&gt; also known as server logs, these logs are printed in &lt;em&gt;JSON&lt;/em&gt;. Process log can include entries such as issues, connections, etc. Messages are similar to this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"t":{"$date":"2020-05-01T15:16:17.180+00:00"},"s":"I", "c":"NETWORK", "id":12345, "ctx":"listener", "msg":"Listening on","attr":{"address":"127.0.0.1"}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Source: &lt;a href="https://docs.mongodb.com/manual/reference/log-messages/" rel="noopener noreferrer"&gt;MongoDB LOG MESSAGES&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Audit Logs&lt;/strong&gt; these logs must be enabled and allows to audit any users actions inside the mongoDB Atlas cluster, like issued command, source IP, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Information about &lt;a href="https://docs.atlas.mongodb.com/database-auditing/" rel="noopener noreferrer"&gt;Enabling auditing logs&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  These two types of logs has several aspects to consider:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Logs are only available for &lt;strong&gt;30 days&lt;/strong&gt;, so in case you need more logs you need to have a process in place that can download these logs files. You can manually download these files, but let be honest, you will forget to do it from time to time.&lt;/li&gt;
&lt;li&gt;Logs are downloaded in &lt;strong&gt;.gz&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;Logs are generated for each node inside the cluster, if you have a cluster with 3 nodes you will have 3 log files. The bigger log file will be the one corresponding to the master node.&lt;/li&gt;
&lt;li&gt;You must required &lt;strong&gt;project read access&lt;/strong&gt; at a minimum to download log files, but in order to enable audit logs you require at least &lt;strong&gt;project owner&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Cluster types &lt;strong&gt;M0&lt;/strong&gt; and &lt;strong&gt;M2/M5&lt;/strong&gt; does not provide downloadable logs, so you cannot replicate these blog entry on your sandbox or free cluster.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More about manually downloading log files from MongoDB Atlas &lt;a href="https://docs.atlas.mongodb.com/mongodb-logs/#std-label-mongodb-logs" rel="noopener noreferrer"&gt;HERE&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  As we talked before...
&lt;/h2&gt;

&lt;p&gt;Downloading each log file on daily basis can be time consuming at least, and a really difficult to maintain activity.&lt;/p&gt;

&lt;h3&gt;
  
  
  THe simplest thing you can do is automate this file download using an script, and it is what we are going to do. We are going to suppose the following:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We have our cluster on MongoDB Atlas.&lt;/li&gt;
&lt;li&gt;We are using &lt;strong&gt;AWS&lt;/strong&gt; as a cloud provider. Maybe in the future i will adapt this code for other cloud providers, but this time we are going to use some services from AWS.&lt;/li&gt;
&lt;li&gt;THis is a simple script that will run on a daily basis inside a Linux &lt;strong&gt;EC2 Instance&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;The user will assing an Instance profile so our EC2 Instance will have access to the following AWS Resources:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AWS S3&lt;/strong&gt; to store the log files&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AWS Parameter Store&lt;/strong&gt; to store the key that allows us to connect to mongo DB Atlas cluster.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;MOngoDB Atlas has a connection with your AWS Infrastructure using one of the following:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;VPC Peer connection&lt;/strong&gt;, more about configure peer connection on MOngo Atlas &lt;a href="https://docs.atlas.mongodb.com/security-vpc-peering/" rel="noopener noreferrer"&gt;HERE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adding a public IP to your instance&lt;/strong&gt; and enablig this public IP inside MOngoDB Atlas &lt;a href="https://docs.atlas.mongodb.com/security/ip-access-list/" rel="noopener noreferrer"&gt;HERE&lt;/a&gt; &lt;strong&gt;THIS IS NOT RECOMMENDED&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  But first, you need some pre requisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create the EC2 Instance and install 

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://docs.mongodb.com/mongocli/stable/install/" rel="noopener noreferrer"&gt;&lt;strong&gt;Mongo CLI&lt;/strong&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html" rel="noopener noreferrer"&gt;AWS CLI&lt;/a&gt; AWS CLI is already installed in AMazon Linux.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Create a S3 Bucket where logs are going to be stored.&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-create-console.html" rel="noopener noreferrer"&gt;Create a PArameter store&lt;/a&gt; to keep the MOngo Atlas key.&lt;/li&gt;

&lt;li&gt;Define an instance profile with the following permissions:
&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s3:Read*
s3:Write*
"ssm:GetParameters"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; Remember to use the specific ARN of your resources, when providing the resource.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate an API KEY to connect to your cluster&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;And assign the permissions:&lt;/p&gt;

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

&lt;p&gt;Store the public key and private key generated inside your parameter stores. &lt;strong&gt;REmember&lt;/strong&gt; to store the values in a &lt;em&gt;key:value&lt;/em&gt; fashion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  cluster_id: "your cluster id",
  public_key: "your public api key from atlas",
  private_key: "your private api key from atlas"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  NOw with all these in place...
&lt;/h2&gt;

&lt;p&gt;Let's move to our code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#! /bin/bash -e

CLUSTERID=$(aws ssm get-parameters --names "mongodb-atlas-key" --with-decryption --query 'Parameters[*].Value' --output text | grep "cluster_id" | cut -f2 -d ":" | cut -d "\"" -f2)

PUBLICKEY=$(aws ssm get-parameters --names "mongodb-atlas-key" --with-decryption --query 'Parameters[*].Value' --output text | grep "public_key" | cut -f2 -d ":" | cut -d "\"" -f2)

PRIVATEKEY=$(aws ssm get-parameters --names "mongodb-atlas-key" --with-decryption --query 'Parameters[*].Value' --output text | grep "private_key" | cut -f2 -d ":" | cut -d "\"" -f2)

CURRENTDATE=`date +%Y%m%d`
NOW=`date '+%F_%H:%M:%S'`
declare -a StringArray=("node-00-00.snvtr.mongodb.net" "node-00-01.snvtr.mongodb.net" "node-00-02.snvtr.mongodb.net")

for hostname in ${StringArray[@]}; do
  echo "Obtaining logs from ${hostname}"
  curl --user ${PUBLICKEY}:${PRIVATEKEY} --digest \
    --header 'Accept: application/gzip' \
    --request GET "https://cloud.mongodb.com/api/atlas/v1.0/groups/${CLUSTERID}/clusters/${hostname}/logs/mongodb.gz" \
    --output "mongodb-${hostname}-${CURRENTDATE}.gz"

  echo "Uploading logs from ${hostname}"
  aws s3 mv "mongodb-${hostname}-${CURRENTDATE}.gz" s3://mongodb-logs/mongodblogs/${NOW}/mongodb-${hostname}-${CURRENTDATE}.gz
done

for hostname in ${StringArray[@]}; do
  echo "Obtaining Audit logs from ${hostname}"
  curl --user ${PUBLICKEY}:${PRIVATEKEY} --digest \
    --header 'Accept: application/gzip' \
    --request GET "https://cloud.mongodb.com/api/atlas/v1.0/groups/${CLUSTERID}/clusters/${hostname}/logs/mongodb-audit-log.gz" \
    --output "mongodb-audit-log-${hostname}-${CURRENTDATE}.gz"

  echo "Uploading Audit logs from ${hostname}"
  aws s3 mv "mongodb-audit-log-${hostname}-${CURRENTDATE}.gz" s3://mongodb-logs/mongodblogs/${NOW}/mongodb-audit-log-${hostname}-${CURRENTDATE}.gz
done

echo ""
echo "End of script execution..."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Let's see each part
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#! /bin/bash -e

CLUSTERID=$(aws ssm get-parameters --names "mongodb-atlas-key" --with-decryption --query 'Parameters[*].Value' --output text | grep "cluster_id" | cut -f2 -d ":" | cut -d "\"" -f2)

PUBLICKEY=$(aws ssm get-parameters --names "mongodb-atlas-key" --with-decryption --query 'Parameters[*].Value' --output text | grep "public_key" | cut -f2 -d ":" | cut -d "\"" -f2)

PRIVATEKEY=$(aws ssm get-parameters --names "mongodb-atlas-key" --with-decryption --query 'Parameters[*].Value' --output text | grep "private_key" | cut -f2 -d ":" | cut -d "\"" -f2)

CURRENTDATE=`date +%Y%m%d`
NOW=`date '+%F_%H:%M:%S'`
declare -a StringArray=("node-00-00.snvtr.mongodb.net" "node-00-01.snvtr.mongodb.net" "node-00-02.snvtr.mongodb.net")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Under this section, we are declaring variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CLUSTERID: this value is obtained directly from the parameter store, the value is decrypted and cut.&lt;/li&gt;
&lt;li&gt;PUBLICKEY: this value is obtained from the parameter store, decrypted and assigned to the variable.&lt;/li&gt;
&lt;li&gt;PRIVATEKEY: this value is obtained from the parameter store using the aws cli command &lt;code&gt;aws ssm get-parameters&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;CURRENTDATE and NOW, are variables that we set to store the log files inside the s3 bucket.&lt;/li&gt;
&lt;li&gt;We also declare the array of cluster nodes names. YOu could also store this values in another parameter store, but as this is not critical you can download write it here.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you may noticed, these approach allows us to keep critical information out of the code, and in case this information changes you will only need to make the change inside the parameter store. NEw values will be obtain on new executions.&lt;/p&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for hostname in ${StringArray[@]}; do
  echo "Obtaining logs from ${hostname}"
  curl --user ${PUBLICKEY}:${PRIVATEKEY} --digest \
    --header 'Accept: application/gzip' \
    --request GET "https://cloud.mongodb.com/api/atlas/v1.0/groups/${CLUSTERID}/clusters/${hostname}/logs/mongodb.gz" \
    --output "mongodb-${hostname}-${CURRENTDATE}.gz"

  echo "Uploading logs from ${hostname}"
  aws s3 mv "mongodb-${hostname}-${CURRENTDATE}.gz" s3://mongodb-logs/mongodblogs/${NOW}/mongodb-${hostname}-${CURRENTDATE}.gz
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;THis &lt;em&gt;for loop&lt;/em&gt; will go through the node names and download the &lt;strong&gt;process logs&lt;/strong&gt;&lt;br&gt;
THen it will store them locally in the instance, and after that it will move them to the s3 bucket using the date and the hostname.&lt;/p&gt;

&lt;p&gt;BAsically, we are making an API CALL to mongoDB Atlas, and we are authenticating ourself using the key generated.&lt;/p&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for hostname in ${StringArray[@]}; do
  echo "Obtaining Audit logs from ${hostname}"
  curl --user ${PUBLICKEY}:${PRIVATEKEY} --digest \
    --header 'Accept: application/gzip' \
    --request GET "https://cloud.mongodb.com/api/atlas/v1.0/groups/${CLUSTERID}/clusters/${hostname}/logs/mongodb-audit-log.gz" \
    --output "mongodb-audit-log-${hostname}-${CURRENTDATE}.gz"

  echo "Uploading Audit logs from ${hostname}"
  aws s3 mv "mongodb-audit-log-${hostname}-${CURRENTDATE}.gz" s3://mongodb-logs/mongodblogs/${NOW}/mongodb-audit-log-${hostname}-${CURRENTDATE}.gz
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;THis &lt;em&gt;for loop&lt;/em&gt; will go through the node names and download the &lt;strong&gt;audit logs&lt;/strong&gt;&lt;br&gt;
THen it will store them locally in the instance, and after that it will move them to the s3 bucket using the date and the hostname.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;You can grab this script&lt;/strong&gt; and put it inside a cronjob to be executed every day.&lt;br&gt;
We are not defining the time frame for the logs, by default is &lt;strong&gt;24 hours&lt;/strong&gt;, by executing this script daily we are donwloading logs from the last 24 hours.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;a href="https://docs.atlas.mongodb.com/reference/api/apiKeys/#programmatic-api-keys" rel="noopener noreferrer"&gt;Programmatic API Keys&lt;/a&gt;
&lt;/h2&gt;

</description>
      <category>mongodb</category>
      <category>atlashackathon</category>
      <category>bash</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Do you want to work with env? let's talk about Conda - the basics</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Thu, 20 Jan 2022 20:45:55 +0000</pubDate>
      <link>https://dev.to/aernesto24/do-you-want-to-work-with-env-lets-talk-about-conda-the-basics-4n0i</link>
      <guid>https://dev.to/aernesto24/do-you-want-to-work-with-env-lets-talk-about-conda-the-basics-4n0i</guid>
      <description>&lt;p&gt;On Python, most of the time, it is a good practice to work with environments, simply because there are different packages or versions to work with between projects, and maintain all that dependencies can be a nightmare on a single environment. There are different options like &lt;strong&gt;venv&lt;/strong&gt; but today we are going to talk a little aboud &lt;strong&gt;CONDA&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conda&lt;/strong&gt; is an open source environment management systems that can be used to install and manage packages too. Ti can be installed on Mac, Linux or Windows, and also provide an &lt;a href="https://www.anaconda.com/enterprise/" rel="noopener noreferrer"&gt;Enterprise version&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Think of it like having several minicomputers inside your computer.&lt;/p&gt;

&lt;p&gt;Basically, you can install any package inside the &lt;a href="https://repo.anaconda.com/" rel="noopener noreferrer"&gt;Anaconda repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It works with any language including &lt;em&gt;Python, R, Java, JavaScript, etc.&lt;/em&gt; But today we are going to work some examples in &lt;em&gt;Python&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Another&lt;/em&gt; aspect to consider, you will need to install miniconda or Anaconda to use Conda and the installation will get you also a version of python.&lt;/p&gt;

&lt;p&gt;For this example i am going to use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Anaconda&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ubuntu 20.04&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; make sure you haver installed &lt;em&gt;wget&lt;/em&gt; on your ubuntu&lt;/p&gt;

&lt;p&gt;Frist of all we are starting by downloading the anaconda script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget -O anaconda.sh https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://repo.anaconda.com/archive/" rel="noopener noreferrer"&gt;HERE&lt;/a&gt; you will find the list of all the available installers&lt;/p&gt;

&lt;p&gt;Then, move to the directory where your &lt;strong&gt;anaconda.sh&lt;/strong&gt; file was stored and execute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bash anaconda.sh
 #After installantion successfully ends 
conda init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If conda init executed correctly you will see something like this on your prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(base) ernestolopez@mypc:~$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;(base)&lt;/strong&gt; will let you know that conda was successfully installed but if you want to make sure, just run &lt;strong&gt;conda info&lt;/strong&gt;&lt;br&gt;
That will provide you with information such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;active environment&lt;/li&gt;
&lt;li&gt;env location&lt;/li&gt;
&lt;li&gt;conda version&lt;/li&gt;
&lt;li&gt;python version&lt;/li&gt;
&lt;li&gt;user config file &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And now we are going to see some useful commands to work with conda.&lt;/p&gt;
&lt;h1&gt;
  
  
  BASIC COMMANDS TO WORK WITH CONDA
&lt;/h1&gt;

&lt;p&gt;We will start by listing our environments&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(base) ernestolopez@mypc:~$ conda env list
# conda environments:
#
base                  *  /home/ernestolopez/anaconda3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see, we only have one environment, so how about if we create another one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(base) ernestolopez@mypc:~$ conda create --name env2
Collecting package metadata (current_repodata.json): done
Solving environment: done

 ## Package Plan ##

  environment location: /home/ernestolopez/anaconda3/envs/env2



Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
 #
 # To activate this environment, use
 #
 #     $ conda activate env2
 #
 # To deactivate an active environment, use
 #
 #     $ conda deactivate

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

&lt;/div&gt;



&lt;p&gt;If we analize this output, we obser two new commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;conda activate env2&lt;/strong&gt; will activate the new environment and automatically we are going to be inside of it&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;conda deactivate&lt;/strong&gt; will deactivate the current environemnt, befor you can delete any environment you will need to deactivate it first.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  OK, Ok
&lt;/h4&gt;

&lt;p&gt;So we created an environment, but we didn't tell the environment that we wanted new packages or any different version right?&lt;br&gt;
Let's create a new environment with an specific python version (&lt;em&gt;3.6&lt;/em&gt;) and a two new packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(base) ernestolopez@mypc:~$ conda create --name=env-demo-36 python=3.6 astor

 #you can add new packages just by adding a space and the name of the package in anaconda repo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When prompt, answer &lt;strong&gt;yes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AN now we will get into this new environment and see the packages listed&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(base) ernestolopez@mypc:~$ conda activate env-demo-36
(env-demo-36) ernestolopez@mypc:~$ 

(env-demo-36) ernestolopez@mypc:~$ conda list
# packages in environment at /home/ernestolopez/anaconda3/envs/env-demo-36:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
_openmp_mutex             4.5                       1_gnu  
astor                     0.8.1            py36h06a4308_0  
ca-certificates           2021.10.26                         h5101ec6_17  
openssl                   1.1.1m               h7f8727e_0  
pip                       21.2.2           py36h06a4308_0  
python                    3.6.13               h12debd9_1  
readline                  8.1.2                h7f8727e_1  
setuptools                58.0.4           py36h06a4308_0  
sqlite                    3.37.0               hc218d9a_0  
tk                        8.6.11               h1ccaba5_0  
wheel                     0.37.1             pyhd3eb1b0_0  
xz                        5.2.5                h7b6447c_0  
zlib                      1.2.11               h7f8727e_4  


 #THis give you a complete list if we want to see a specific package we can use 

(env-demo-36) ernestolopez@mypc:~$ conda list python
# packages in environment at /home/ernestolopez/anaconda3/envs/env-demo-36:
#
# Name                    Version                   Build  Channel
python                    3.6.13               h12debd9_1 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; &amp;gt; We can start developing inside this environment by moving to the folfer of the env &lt;strong&gt;/home/ernestolopez/anaconda3/envs/env-demo-36&lt;/strong&gt; and writing &lt;em&gt;code .&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We can update packages inside our environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env-demo-36) ernestolopez@mypc:~/anaconda3/envs/env-demo-36$ conda update python
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/ernestolopez/anaconda3/envs/env-demo-36

  added / updated specs:
    - python


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    astor-0.8.1                |   py39h06a4308_0          47 KB
    ------------------------------------------------------------
                                           Total:          47 KB

The following NEW packages will be INSTALLED:

  tzdata             pkgs/main/noarch::tzdata-2021e-hda174b7_0

The following packages will be UPDATED


Proceed ([y]/n)? y

Downloading and Extracting Packages
astor-0.8.1          | 47 KB     | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(env-demo-36) ernestolopez@mypc:~/anaconda3/envs/env-demo-36$ conda list python
# packages in environment at /home/ernestolopez/anaconda3/envs/env-demo-36:
#
# Name                    Version                   Build  Channel
python                    3.9.7                h12debd9_1  
(env-demo-36) 

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

&lt;/div&gt;



&lt;p&gt;WE have just update Python, and now our beautiful name &lt;strong&gt;env-demo-36&lt;/strong&gt; is not valid anymore because we are not in 3.6 version&lt;/p&gt;

&lt;p&gt;In Conda, you cannot rename an environment, so what we want to do es clone our environemnt with a new name, and delete the old one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env-demo-36) ernestolopez@mypc:~/anaconda3/envs/env-demo-36$ conda create --name env-demo-39 --copy --clone env-demo-36
Source:      /home/ernestolopez/anaconda3/envs/env-demo-36
Destination: /home/ernestolopez/anaconda3/envs/env-demo-39
Packages: 22
Files: 0
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate env-demo-39
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(env-demo-36) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you list both environments, you will see that both are similar.&lt;/p&gt;

&lt;p&gt;It is time to close this basic tutorial, and now we are going to delete our environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env-demo-36) elopez@winterfell:~/anaconda3/envs/env-demo-36$ conda env list
# conda environments:
#
base                     /home/ernestolopez/anaconda3
env-demo-36           *  /home/ernestolopez/anaconda3/envs/env-demo-36
env-demo-39              /home/ernestolopez/anaconda3/envs/env-demo-39
env2                     /home/ernestolopez/anaconda3/envs/env2

(env-demo-36) ernestolopez@mypc:~/anaconda3/envs/env-demo-36$ conda env remove --name env2

Remove all packages in environment /home/ernestolopez/anaconda3/envs/env2:

(env-demo-36)  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you list your environments again, it will not appear, but what happens if i try to delete my current environment?? *&lt;em&gt;(env-demo-36) *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It will provoke an error, remember i just told you, &lt;strong&gt;you need to deactivate your env previous to delete it&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(env-demo-36) ernestolopez@mypc:~/anaconda3/envs/env-demo-36$ conda env remove --name env-demo-36

CondaEnvironmentError: cannot remove current environment. deactivate and run conda remove again

(env-demo-36) ernestolopez@mypc:~/anaconda3/envs/env-demo-36$ conda deactivate
(base) ernestolopez@mypc:~/anaconda3/envs/env-demo-36$ conda env remove --name env-demo-36

Remove all packages in environment /home/ernestolopez/anaconda3/envs/env-demo-36:


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

&lt;/div&gt;



&lt;h2&gt;
  
  
  AND THAT's IT!!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Hope this information was useful!!!
&lt;/h3&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>conda</category>
      <category>devops</category>
    </item>
    <item>
      <title>Working with events in Oracle Cloud Infrastructure Part 1: service basics</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Tue, 11 Jan 2022 22:55:21 +0000</pubDate>
      <link>https://dev.to/aernesto24/working-with-events-in-oracle-cloud-infrastructure-part-1-service-basics-44kd</link>
      <guid>https://dev.to/aernesto24/working-with-events-in-oracle-cloud-infrastructure-part-1-service-basics-44kd</guid>
      <description>&lt;p&gt;&lt;strong&gt;Oracle Cloud Infrastructure Events&lt;/strong&gt; is a service that allows you to create some automation base on change of state in a service, or maybe based in some sort of input received. Now, let get a step back, and &lt;em&gt;Event&lt;/em&gt; is the occurrence of a particular situation. For this situations to be useful, events needs to be with some kind of information, for example, instance name, object name, status code, etc. The information can provide the automation something to work with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Events&lt;/strong&gt; are the base of serverless architecture, sometimes also referred to &lt;strong&gt;event-driven architecture&lt;/strong&gt;. Additionally, events are crucial for contemporary software architectures as enables to decouple services, help to make software &lt;strong&gt;asynchronous calls&lt;/strong&gt; and facilitate scaling processes.&lt;/p&gt;

&lt;h4&gt;
  
  
  An example of an event driven architecture:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;You develop an &lt;strong&gt;image processing app&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Everytime a new image is uploaded to a bucket &lt;strong&gt;it triggers an event&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;This event calls a &lt;strong&gt;function&lt;/strong&gt; that grab that image and create a thumbnail &lt;strong&gt;from it&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;thumbnail&lt;/strong&gt; is stored in another bucket.&lt;/li&gt;
&lt;li&gt;This triggers another event that &lt;strong&gt;sends an email notification&lt;/strong&gt; to the client. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; OCI function is a serverless solution from OCI, that allows you to run a single purpose software without provisioning hardware or VMs, the software runs base on an event or a schedule job, it is like having functions as a service. More from Functions &lt;a href="https://docs.oracle.com/en-us/iaas/Content/Functions/Concepts/functionsoverview.htm" rel="noopener noreferrer"&gt;HERE&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting back to OCI Events, some of the important characteristics are:
&lt;/h3&gt;




&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;Event service use JSON object to define the event rules&lt;/strong&gt;. 
You can think of a &lt;strong&gt;rule like the filter&lt;/strong&gt; that will determine which events are important to consider, to determine what are going to be your inputs. Basically, &lt;strong&gt;Rules triggers actions&lt;/strong&gt;. An example of a rule logic can be:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MATCH event WHERE (
  eventType EQUALS ANY OF (
  com.oraclecloud.computeapi.launchinstance.end
  )
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This event will trigger when a new &lt;a href="https://docs.oracle.com/en-us/iaas/Content/Compute/Concepts/computeoverview.htm#:~:text=An%20Oracle%20Cloud%20Infrastructure%20VM,software%20stack%2C%20and%20networking%20infrastructure." rel="noopener noreferrer"&gt;compute instance&lt;/a&gt; is created&lt;/p&gt;

&lt;h5&gt;
  
  
  But...
&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;Where is the JSON part??&lt;/strong&gt;&lt;br&gt;
On the event, itself, let see an example of an event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "eventType": "com.oraclecloud.computeapi.launchinstance.end",
  "cloudEventsVersion": "0.1",
  "eventTypeVersion": "2.0",
  "source": "ComputeApi",
  "eventTime": "2019-08-16T12:07:42.794Z",
  "contentType": "application/json",
  "data": {
    "compartmentId": "ocid1.compartment.oc1..unique_ID",
    "compartmentName": "example_compartment",
    "resourceName": "my_instance",
    "resourceId": "ocid1.instance.oc1.phx.unique_ID",
    "availabilityDomain": "availability_domain",
    "additionalDetails": {
      "imageId": "ocid1.image.oc1.phx.unique_ID",
      "shape": "VM.Standard2.1",
      "type": "CustomerVmi"
    }
  },
  "eventID": "unique_ID",
  "extensions": {
    "compartmentId": "ocid1.compartment.oc1..unique_ID"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an example of an instance that have been just created, and will trigger the event.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;You can add conditions or filters to further narrow your events&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;During an event rule configuration, you can add some attributes to further filter your results&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpnrovo3flyxnhuocb40.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpnrovo3flyxnhuocb40.png" alt="Adding attribute to the rule" width="800" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On this example&lt;/strong&gt; we are filtering results from the event type, for changes only on &lt;strong&gt;Sandbox and dev&lt;/strong&gt; compartments, the whole logic looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MATCH event WHERE (
  eventType EQUALS ANY OF (
  com.oraclecloud.computeapi.launchinstance.end
  )
  AND (
  compartmentName MATCHES ANY OF (
  Sandbox,
  dev
  )
 )
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additional to this, we can add &lt;strong&gt;Filter conditions&lt;/strong&gt; based on Tags&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MATCH event WHERE (
  eventType EQUALS ANY OF (
  com.oraclecloud.computeapi.launchinstance.end
  )
  AND (
  compartmentName MATCHES ANY OF (
  Sandbox,
  dev
  )
  definedTags INCLUDES ANY OF (
  Oracle-Tags.CreatedBy.elopez
  )
 )
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visually something like:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37afhkz6yk5g4kykfvr3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37afhkz6yk5g4kykfvr3.png" alt="Rule conditions configuration" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basically&lt;/strong&gt; this event will trigger everytime an instance is launch on &lt;em&gt;Sandbox&lt;/em&gt; OR &lt;em&gt;dev&lt;/em&gt; compartments by the user &lt;em&gt;elopez&lt;/em&gt;.&lt;/p&gt;



&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;Rules most specify and action&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main objective for the rules is to provoke something when they are triggered, otherwise will be useless.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Actions are responses defined for event matched&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Actions can be created using:&lt;br&gt;
&lt;strong&gt;&lt;a href="https://docs.oracle.com/en-us/iaas/Content/Notification/home.htm#top" rel="noopener noreferrer"&gt;Notifications&lt;/a&gt;&lt;/strong&gt; send the messages to a notification service which can send it to endpoints that are subscribe to the topic&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frhfx6lgpbd97ekk5gx90.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frhfx6lgpbd97ekk5gx90.png" alt="notifications" width="800" height="115"&gt;&lt;/a&gt;&lt;br&gt;
 These could be: an email address, email group, slack channel, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://docs.oracle.com/en-us/iaas/Content/Streaming/home.htm#top" rel="noopener noreferrer"&gt;Streaming&lt;/a&gt;&lt;/strong&gt; using this service you will ingest your events into a data streams to obtain further analysis and intelligence over this data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://docs.oracle.com/en-us/iaas/Content/Functions/Concepts/functionsoverview.htm#Overview_of_Functions" rel="noopener noreferrer"&gt;Functions&lt;/a&gt;&lt;/strong&gt; functions can be executed based on events received. &lt;strong&gt;Quick example:&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;you can have an event that triggers every time a new instance is created and this will execute a function that configure monitoring for that new instance.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;You need to add permissions so the Events service can call the action services&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Take into consideration&lt;/strong&gt; any action is deny by default on OCI so you will need to create a policy that permit the Events service to execute the actions.&lt;/p&gt;

&lt;p&gt;Basic permission you will need is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Allow service cloudEvents to use ons-topic in tenancy
Allow service cloudEvents to use functions-family in tenancy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is for the &lt;em&gt;Tenancy&lt;/em&gt; but you can assign it to an specific &lt;em&gt;Compartment&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Allow service cloudEvents to use ons-topic in compartment DEV
Allow service cloudEvents to use functions-family in compartment DEV
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More about compartments &lt;a href="https://dev.to/aernesto24/7-things-to-know-about-compartments-on-oracle-cloud-infrastructure-4l1p"&gt;HERE&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>cloud</category>
      <category>eventdriven</category>
      <category>oracle</category>
    </item>
    <item>
      <title>I want to use OCI Python SDK, where should i begin?</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Fri, 07 Jan 2022 20:00:33 +0000</pubDate>
      <link>https://dev.to/aernesto24/i-want-to-use-oci-python-sdk-where-should-i-begin-4co3</link>
      <guid>https://dev.to/aernesto24/i-want-to-use-oci-python-sdk-where-should-i-begin-4co3</guid>
      <description>&lt;p&gt;&lt;strong&gt;SDK&lt;/strong&gt; Refers to a set of software tools used to create software that allow us to manage a specific platform. These tools can include: &lt;em&gt;libraries, processes, documentation, etc&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;OCI python SDK&lt;/strong&gt; allows us to write code to manage resources in Oracle cloud&lt;/p&gt;

&lt;p&gt;You can download the SDK from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/oracle/oci-python-sdk/releases" rel="noopener noreferrer"&gt;GITHUB&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/oci/" rel="noopener noreferrer"&gt;PIP Install&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;easiest way&lt;/strong&gt; is using the pip install, by executing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install oci
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, remember to add this line to your python code, so you can be able to use the SDK&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt;import oci
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have follow until here, you may encounter an error, when trying to use any command on the SDK, and &lt;em&gt;why is that?&lt;/em&gt; - well, in order to connect to OCI resources, you need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An &lt;strong&gt;OCI Account&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;A user created in that account, in a group with a policy that grants manage permissions or lower. Examples on policies can be found &lt;a href="https://www.youtube.com/watch?v=Cl-RmrACTI8" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Configure &lt;strong&gt;OCI CLI profile&lt;/strong&gt; on your local computer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I have &lt;strong&gt;some good news&lt;/strong&gt;, you can create a free account in Oracle Cloud and get 300USD credits to test resources. Instructions &lt;a href="https://www.oracle.com/cloud/free/" rel="noopener noreferrer"&gt;HERE&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second&lt;/strong&gt;, configure the CLI is easy you just need to (&lt;strong&gt;This is for MAC&lt;/strong&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; #Update brew and install cli
brew update &amp;amp;&amp;amp; brew install oci-cli

 #verify oci installation
oci --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take a look into the &lt;a href="https://docs.brew.sh/Installation" rel="noopener noreferrer"&gt;Homebrew documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before using the CLI&lt;/strong&gt;, you need to configure the config file that will contain the required credentials and information for working with Oracle Cloud Infrastructure. By default this file is stored in : &lt;code&gt;~/.oci/config&lt;/code&gt; but you can change it.&lt;/p&gt;

&lt;p&gt;So, in order to generate the config file you need to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; #Move to your home directory and create the .oci folder
mkdir .oci

 #move to the folder and create the config file
cd .oci
touch config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can &lt;strong&gt;vi&lt;/strong&gt; this file and enter something similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ADMIN_USER]
user=ocid1.user.oc1..&amp;lt;unique_ID&amp;gt;
fingerprint=&amp;lt;your_fingerprint&amp;gt;
key_file=keys/admin_key.pem
tenancy = ocid1.tenancy.oc1..&amp;lt;unique_ID&amp;gt;
region = us-phoenix-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;[ADMIN_USER]&lt;/strong&gt; &amp;gt; you can name this anything youu want, but remember the name as you will use it with Python sdk.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;user&lt;/strong&gt; &amp;gt; here you need to enter the user ocid for the IAM user you created at the beginning. &lt;em&gt;OCID is the unique resource identifier that Oracle cloud infrastructure provide to each resource&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;fingerprint&lt;/strong&gt; &amp;gt; refers to the fingerprint of the public key you configure to your user. All the relevant information related to his can be found &lt;a href="https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;key_file&lt;/strong&gt; &amp;gt; the .pem file you generated. You should use the complete path if your keys are located in a different directory &lt;code&gt;/Users/elopez/.ssh/admin_key.pem&lt;/code&gt;. Detail information for &lt;a href="https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm#two" rel="noopener noreferrer"&gt;How to Generate an API Signing Key&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;tenancy&lt;/strong&gt; &amp;gt; your tenancy OCID. Details on &lt;a href="https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm#five" rel="noopener noreferrer"&gt;how to obtain my tenancy OCID&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;region&lt;/strong&gt; &amp;gt; the region that you are subscribed to (region identifier), &lt;a href="https://docs.oracle.com/en-us/iaas/Content/General/Concepts/regions.htm#top" rel="noopener noreferrer"&gt;Regions and Availability Domains&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  NOW, WE can start testing some stuff with python SDK.
&lt;/h3&gt;

&lt;p&gt;First you need to establish the connection with OCI, and provide your software with the credentials that will be using.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; config = oci.config.from_file(
...     "~/.oci/config",
...     "ADMIN_USER")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Another approach&lt;/strong&gt; could be to store this information in a &lt;strong&gt;.env&lt;/strong&gt; file (that you should include into your &lt;em&gt;.gitignore&lt;/em&gt;)&lt;br&gt;
and reference the file into your code&lt;br&gt;
&lt;/p&gt;

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

config = oci.config.from_file(os.environ.get("CONFIG_PATH"), os.environ.get("OCI_PROFILE"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and your &lt;strong&gt;.env&lt;/strong&gt; file can look 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;CONFIG_PATH = "~/.oci/config"
OCI_PROFILE = "ADMIN_USER"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the minimum required to connect with OCI, and will help you establish connection with other services as for example compute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; # Initialize compute client with default config file
compute_client = oci.core.ComputeClient(config)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or for the monitoring service&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; # Initialize compute client with default config file
monitoring_client = oci.monitoring.MonitoringClient(config)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now, you can use this to get, for example, a list of compute instances inside a container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;compartment_id_selected = os.environ.get("COMPARTMENT_ID")

list_instances_response = compute_client.list_instances(compartment_id=compartment_id_selected, sort_order="DESC", lifecycle_state="RUNNING")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the basic steps to start working with OCI python SDK. &lt;/p&gt;




&lt;h1&gt;
  
  
  Additional Resources
&lt;/h1&gt;

&lt;p&gt;More about &lt;a href="https://dev.to/aernesto24/7-things-to-know-about-compartments-on-oracle-cloud-infrastructure-4l1p"&gt;OCI Containers&lt;/a&gt;&lt;br&gt;
My personal &lt;a href="https://github.com/aernesto24/oci-elopez-useful-scripts" rel="noopener noreferrer"&gt;GITHUB OCI REPO&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Oracle&lt;/strong&gt; has develop a complete API reference and also it helps you by providing code examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://oracle-cloud-infrastructure-python-sdk.readthedocs.io/en/latest/" rel="noopener noreferrer"&gt;ORACLE SDK Reference&lt;/a&gt;. Look for the API Reference on the left pane menu.
Examples can be seen like this one:
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3iy54iuiipy28iycemr.png" alt="Examples reference" width="800" height="622"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# URL &amp;gt; https://docs.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/core/update_instance_configuration.py.html

# This is an automatically generated code sample.
# To make this code sample work in your Oracle Cloud tenancy,
# please replace the values for any parameters whose current values do not fit
# your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
# boolean, number, and enum parameters with values not fitting your use case).

import oci

# Create a default config using DEFAULT profile in default location
# Refer to
# https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File
# for more info
config = oci.config.from_file()


# Initialize service client with default config file
core_client = oci.core.ComputeManagementClient(config)


# Send the request to service, some parameters are not required, see API
# doc for more info
update_instance_configuration_response = core_client.update_instance_configuration(
    instance_configuration_id="ocid1.test.oc1..&amp;lt;unique_ID&amp;gt;EXAMPLE-instanceConfigurationId-Value",
    update_instance_configuration_details=oci.core.models.UpdateInstanceConfigurationDetails(
        defined_tags={
            'EXAMPLE_KEY_4bccp': {
                'EXAMPLE_KEY_l4nah': 'EXAMPLE--Value'}},
        display_name="EXAMPLE-displayName-Value",
        freeform_tags={
            'EXAMPLE_KEY_s14GL': 'EXAMPLE_VALUE_ZZgDFtoA0GvgolAJlyPw'}),
    opc_retry_token="EXAMPLE-opcRetryToken-Value",
    if_match="EXAMPLE-ifMatch-Value")

# Get the data from response
print(update_instance_configuration_response.data)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>oracle</category>
      <category>cloud</category>
      <category>beginners</category>
      <category>python</category>
    </item>
    <item>
      <title>My personal recommendations to get the OCI Oracle Cloud Infrastructure Architect Associate certification</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Fri, 31 Dec 2021 23:31:40 +0000</pubDate>
      <link>https://dev.to/aernesto24/my-experience-with-ocioracle-cloud-infrastructure-architect-associatecertification-4i42</link>
      <guid>https://dev.to/aernesto24/my-experience-with-ocioracle-cloud-infrastructure-architect-associatecertification-4i42</guid>
      <description>&lt;p&gt;On December 30th, I achieved the &lt;strong&gt;Oracle Cloud Infrastructure Architect Associate certification&lt;/strong&gt; after passing the exam &lt;strong&gt;OCI Architect 2021 Associate [1Z0-1072-21]&lt;/strong&gt;, just 3 month after even knowing that Oracle had their own Cloud computing offer, and here i plan to write my personal recommendations so you can prepare to this exam.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First of all,&lt;/strong&gt; you need to know that the exam is not a walk in the meadow, most of the question has two or three possible options but only one is the best, another questions are related so you know that if you have one wrong the other one is wrong to &lt;em&gt;(Or yo can play varying the answers and see what happens)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;With certifications, &lt;strong&gt;my personal recommendation&lt;/strong&gt; is to completely avoid exam dumps, Maybe you will find the answers but you are not learning and something even worst, you will lower the appreciation level for that certification and will affect people that studied for their tests.&lt;/p&gt;

&lt;p&gt;Now, let start:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Open an OCI free account,&lt;/strong&gt; instruction &lt;a href="https://www.oracle.com/cloud/free/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. You will need to practice, practice, practice. Or at least get to know where the services are located and what are the options requested to configure them. Also, The &lt;a href="https://cloud.oracle.com" rel="noopener noreferrer"&gt;web console&lt;/a&gt; is constantly under development, features are added or updated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Start by studying for the Oracle Foundation certification&lt;/strong&gt; and take the  &lt;strong&gt;OCI Foundations 2021 Associate [1Z0-1085-21]&lt;/strong&gt; test. The training videos under Oracle University are well explained, and contain all the information and examples you will need. You can start &lt;a href="https://learn.oracle.com/ols/learning-path/become-an-oci-foundation-associate/35644/98057" rel="noopener noreferrer"&gt;HERE&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;After achieving the foundation certification, take the trainings for the Associate level&lt;/strong&gt;, again, the video trainings from Oracle are complete and contain all the information you required for the test. Training videos can be found &lt;a href="https://learn.oracle.com/ols/learning-path/become-an-oci-architect-associate/35644/98012" rel="noopener noreferrer"&gt;HERE&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Follow up the practice videos&lt;/strong&gt; in your own account, nothing will help you more than doing it yourself.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Read the services FAQs pages&lt;/strong&gt;, this will provide in depth information about compute instances, storage services, database services, etc. Some questions can be easily resolved knowing the information that appears on those resources.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.oracle.com/cloud/compute/faq.html" rel="noopener noreferrer"&gt;Compute Service FAQs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oracle.com/cloud/storage/block-volumes/faq/" rel="noopener noreferrer"&gt;Block Volumes FAQs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oracle.com/cloud/storage/object-storage/faq/" rel="noopener noreferrer"&gt;Object Storage FAQs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oracle.com/cloud/networking/virtual-cloud-network-faq.html" rel="noopener noreferrer"&gt;VCN FAQs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oracle.com/database/technologies/datawarehouse-bigdata/adb-faqs.html" rel="noopener noreferrer"&gt;Autonomous Database FAQs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Exposure is important&lt;/strong&gt;, besides practicing you can also see the youtube videos from Oracle learning channel, they developed an &lt;a href="https://www.youtube.com/playlist?list=PLh-_2FBnEG187w8pB-8GVtCe_VUs74rS2" rel="noopener noreferrer"&gt;Oracle Cloud Infrastructure Certified Architect Associate - 1Z0-1072 Exam Preparation&lt;/a&gt; video path that contains useful information for day to day job.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Personally, I like to complement my learning with some reading&lt;/strong&gt; so i bought the following book &lt;a href="https://www.amazon.com.mx/gp/product/126045259X/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&amp;amp;psc=1" rel="noopener noreferrer"&gt;Oracle Cloud Infrastructure Architect Associate All-In-One Exam Guide (Exam 1z0-1072)&lt;/a&gt;. This book was developed for a previous version of the exam, but provides some useful commands for day to day job, that could also help you understand some concepts. Example, to upload a multipart file with 5 parallel threads: &lt;br&gt;&lt;br&gt;
&lt;code&gt;oci os object put -ns &amp;lt;object-storage-namespaces&amp;gt; -bn &amp;lt;bucket-name&amp;gt; --file &amp;lt;filepath/filename&amp;gt; --name &amp;lt;object_name_on_bucket&amp;gt; --part-size &amp;lt;size in MB&amp;gt; --parallel-upload-count 5&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Take notes&lt;/strong&gt;, this is important, you can write those notes on paper or use software, i took notes in a txt file using my IDE. Those notes can help you focus on the important subjects.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Last, but not least, go through the Practice Exam: Oracle Cloud Infrastructure Architect Associate Certification&lt;/strong&gt; it contains useful information, and a couple of question can go to the final test or similar ones.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; also a useful, but not needed resource are the blogs, specially the architecture related posts. This is not mandatory but it can provide you with extra knowledge.&lt;/p&gt;

&lt;p&gt;I hope this help you to achieve this certification. Good Luck.&lt;/p&gt;

</description>
      <category>certification</category>
      <category>oracle</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Quickops 3: too many connections to my database and what can i do</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Thu, 23 Dec 2021 23:24:15 +0000</pubDate>
      <link>https://dev.to/aernesto24/quickops-3-lookout-for-connections-to-my-database-and-what-to-do-with-that-557f</link>
      <guid>https://dev.to/aernesto24/quickops-3-lookout-for-connections-to-my-database-and-what-to-do-with-that-557f</guid>
      <description>&lt;p&gt;From time to time you may try to connect to your database cluster and receive an error similar to this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;mysqli_connect(): Too many connections&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this case, new services that try to connect to your database may start failing, and even your &lt;strong&gt;admin&lt;/strong&gt; users will not get to the cluster.&lt;/p&gt;

&lt;p&gt;So, &lt;strong&gt;How are we going to solve this issue?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In my experience you have one of the 3 following options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Restart the cluster or service:&lt;/strong&gt; This can provide potential risks of data loss and it doesn't even resolve the issue or provide useful information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wait unit a connection is releases&lt;/strong&gt; and connect to your database. This could be a quick solution or it can take forever.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the services that connect to the cluster and release connections&lt;/strong&gt;. Under this approach you need to review applications configuration's files and look for a service that is not critical and stop it by a moment so you can connect to the cluster with your admin user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Now&lt;/strong&gt;, suppose you manage to get a connection and enter the server or cluster.&lt;/p&gt;

&lt;p&gt;The following query will provide you with information about users connected to the system and how many connections each user have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select user, COUNT(*) as c from information_schema.processlist GROUP BY user ORDER BY c DESC LIMIT 10;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select user,count(*) as connections from INFORMATION_SCHEMA.PROCESSLIST group by user order by connections;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can even see the status of the connections:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT state, COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST GROUP BY state;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will give you the usernames that are consuming the majority of connections.&lt;/p&gt;

&lt;p&gt;But we can go further and increase the connection count&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; show variables like "max_connections";
--------------
show variables like "max_connections"
--------------
show variables like "max_connections"
--------------
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 100  |
+-----------------+-------+
1 row in set (0.08 sec)

set global max_connections = 500;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Consider that connections increase resources consumption so special care needs to be taken.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This second part is not a good approach...&lt;br&gt;
&lt;strong&gt;Why?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Suppose there is a service that, after a new version release, opens connections to our database but it never closes the connections. &lt;/li&gt;
&lt;li&gt;Even if you have more connections slots available eventually you will have this problem again.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  So, A better approach is to:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Use the information obtainer to detect &lt;strong&gt;the service or services&lt;/strong&gt; that are consuming most connections.&lt;/li&gt;
&lt;li&gt;Review the service config files to detect the amount of connections that the service should use or what is the size of the &lt;strong&gt;pool&lt;/strong&gt; configured.&lt;/li&gt;
&lt;li&gt;If it is too high. Talk with the team to see if all that connections are necessary, or if it can be lowered down.&lt;/li&gt;
&lt;li&gt;In case the connection pool size is a &lt;strong&gt;small number&lt;/strong&gt;, contact the team it is probably a bug in the software.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are in an emergency and needs to release resources you can either stop a service or use this commands:&lt;br&gt;
&lt;/p&gt;

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

 #Find a process that you can kill

kill &amp;lt;PID&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Care with killing processes this is not a best practice until you have a better diagnose of the issue.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>mysql</category>
      <category>troubleshoot</category>
      <category>database</category>
      <category>systems</category>
    </item>
    <item>
      <title>3 ways to use MongoDB without cost (Atlas, mtools, Docker)</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Sat, 18 Dec 2021 01:39:23 +0000</pubDate>
      <link>https://dev.to/aernesto24/3-ways-to-test-mongodb-without-cost-45bd</link>
      <guid>https://dev.to/aernesto24/3-ways-to-test-mongodb-without-cost-45bd</guid>
      <description>&lt;p&gt;&lt;strong&gt;MongoDB&lt;/strong&gt; is a general-purpose no sql database which provides certain capabilities like replication between nodes, sharding, secondary indexes, range queries, sorting, aggregations, and geospatial indexes. MongoDB is a &lt;strong&gt;document-oriented&lt;/strong&gt; database where rows (from relational database) is replaced by documents which can have any fields inside and you can have more information on one document versus another from the same database. This last point means that there is no predefined schemas.&lt;/p&gt;

&lt;p&gt;At the heart of MongoDB there is a &lt;code&gt;key:value&lt;/code&gt; so if you see a document representation is similar to JSON or map. And can be as simple as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"Salute": "Hello Peter!"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So Documents are the basic form of data in mongoDB and a collection is similar to have a table.&lt;/p&gt;

&lt;p&gt;That's all that we will talk about the basics for MongoDB, because this is a post of testing for free.&lt;/p&gt;

&lt;p&gt;Next i am going to present 3 ways you can test your mongoDB database without incurring in any extra cost.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;1. MongoDB Atlas Free Cluster&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;MongoDB Atlas offers a Database as a service with MongoDB Atlas, as part of their offer you can create a free cluster (&lt;em&gt;Always free as long as you keep in this tier&lt;/em&gt;) that has similar functionality that a production one.&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://docs.atlas.mongodb.com/tutorial/deploy-free-tier-cluster/" rel="noopener noreferrer"&gt;MongoDB Atlas documentation&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Free clusters never expire, and provide access to a subset of Atlas features and functionality.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Some of the limitations are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can only have &lt;strong&gt;one&lt;/strong&gt; free cluster per project.&lt;/li&gt;
&lt;li&gt;You can't upgrade the MongoDB version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;M0&lt;/strong&gt; tier is the only one available to deploy free cluster.&lt;/li&gt;
&lt;li&gt;Replication factor is &lt;strong&gt;3 nodes&lt;/strong&gt;, and yes, yo have 3 nodes on free cluster, so replication a similar to prod escenario is easy.&lt;/li&gt;
&lt;li&gt;No predefined &lt;strong&gt;replica set tag&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;you cannot test &lt;strong&gt;primary failover, configure encryption at rest or enable auditing&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Oh i forgot to mention, a &lt;strong&gt;ReplicaSet&lt;/strong&gt; is a group of mongo processes (servers, VMs, Containers, etc) that maintain the same data set. At a minimum it is recommended to have a primary node and two replication or secondary node. Also you can have a Primary node, a secondary node and an arbiter (smaller process just to elect a new primary) but this is not recommended.&lt;/p&gt;

&lt;p&gt;So your free tier cluster can be seen as this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Funbdk1v0jvi05dvyci8j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Funbdk1v0jvi05dvyci8j.png" alt="Cluster0 Sandbox" width="800" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shared&lt;/strong&gt;, as can be seen in the image refers that the nodes are deployed on shared environment so you cannot configure disk size, memory size, etc.&lt;/p&gt;

&lt;p&gt;And, &lt;strong&gt;How can you create your free cluster?&lt;/strong&gt; yo may ask...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First of all&lt;/strong&gt; go to &lt;a href="https://account.mongodb.com/account/register?tck=docs_atlas&amp;amp;_ga=2.33670369.1905865679.1639760133-686843528.1638558648" rel="noopener noreferrer"&gt;MongoDB Atlas registration page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you have the option to fill al the fields or even better use your google account to sign up, and that's it.&lt;/p&gt;

&lt;p&gt;Now, to create the free cluster:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on Build a Cluster&lt;/li&gt;
&lt;li&gt;Select the option of Starters Cluster or Shared Cluster.&lt;/li&gt;
&lt;li&gt;Select your cloud provider. Not all providers or regions support the &lt;strong&gt;free cluster&lt;/strong&gt;. I personally recommends use &lt;strong&gt;AWS with us-east-1 region&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;M0 Sandbox&lt;/strong&gt; tier as this corresponds to the free tier.&lt;/li&gt;
&lt;li&gt;Enter a name for your cluster
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fca24xab86p20bnzwydo1.png" alt="Enter a name for your cluster" width="800" height="177"&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;strong&gt;Create Cluster&lt;/strong&gt; and that is all you need to create your cluster, this process will take around 10 min, so you can go and get a cup of coffee.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, after you cluster is ready, the &lt;strong&gt;First Thing&lt;/strong&gt; you need to do is provide access to your local IP. MongoDB Atlas use a whitelisting approach for this.&lt;/p&gt;

&lt;p&gt;On your MongoDB Atlas interface, move to your project and under security click on &lt;strong&gt;Network Access&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft3pe3mfd3xq8fe16e92i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft3pe3mfd3xq8fe16e92i.png" alt="Network Access mongo Atlas" width="160" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then&lt;/strong&gt;, click on &lt;strong&gt;Add IP Address&lt;/strong&gt; &lt;br&gt;
You have the option on enter and IP in CIDR notation, example &lt;code&gt;188.188.188.21/32&lt;/code&gt;&lt;br&gt;
Another option is to provide access to any IP by using &lt;code&gt;0.0.0.0/0&lt;/code&gt;&lt;br&gt;
Or Click &lt;strong&gt;Add Current IP Address&lt;/strong&gt; and automatically will add your public IP.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; you can even configure a temporary access for 6 hrs, 1 day or 1 week.&lt;/p&gt;

&lt;p&gt;Next Step is to create a user to access the cluster , this is different from the user you created at the beginning, this new user is for database access, the previous one was for &lt;strong&gt;MongoDB Atlas platform administration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Enter the important information and provide the permissions through &lt;strong&gt;Built-in Role&lt;/strong&gt; more info &lt;a href="https://docs.mongodb.com/manual/reference/built-in-roles/" rel="noopener noreferrer"&gt;HERE&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtpm7dug87aqws045e3y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtpm7dug87aqws045e3y.png" alt="create mongo user account" width="799" height="1332"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  One of the main advantages
&lt;/h5&gt;

&lt;p&gt;of MongoDB Atlas is that allows you to find the exact information you need in an easy way. In this case, to test the access we will connect using mongo shell from our laptop.&lt;/p&gt;

&lt;p&gt;you can find the connection URI here&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5rdtbxgi4pfs3hdq7knp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5rdtbxgi4pfs3hdq7knp.png" alt="Connection URI Atlas" width="663" height="128"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the next page, select Connect using MongoShell and it will show you something similar to:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzfyzhi9p30earecby2y8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzfyzhi9p30earecby2y8.png" alt="connect to mongo atlas" width="800" height="666"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; it also provides the required information to download the mongo shell in your local system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; it also provides you with the connection URI and full driver code for several programming languages. Example:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8issaczp2ibbftp3yah4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8issaczp2ibbftp3yah4.png" alt="python connection to mongodb atlas" width="800" height="628"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Getting back to our example. Just add the &lt;strong&gt;username&lt;/strong&gt; you created previously and add the ip when it is requested.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  .ssh  mongosh "mongodb+srv://cluster0.xxxxx.mongodb.net/myFirstDatabase" --username eltest01
Enter password: **********************
Current Mongosh Log ID: xxxxxxxxxxxxxxxxxxxxxxxx
Connecting to:      mongodb+srv://cluster0.xxxxx.mongodb.net/myFirstDatabase
Using MongoDB:      4.4.10
Using Mongosh:      1.1.7

For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

Atlas atlas-xxxxx-shard-0 [primary] myFirstDatabase&amp;gt; show dbs
m201    119 MB
admin   373 kB
local  7.16 GB
Atlas atlas-xxxxx-shard-0 [primary] myFirstDatabase&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;2. Creating a docker container with mongodb official Image&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; The image that we use here is a community edition, MongoDB does provides an Enterprise Server that can include some cost.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;, we need to remember that container are self-contained without default access to the host, and also that containers can be considered ephemeral, so as soon as the container is &lt;strong&gt;terminated&lt;/strong&gt;, any data inside of it will be lost.&lt;/p&gt;

&lt;p&gt;If we want to have persistent storage we need to create a &lt;strong&gt;local directory&lt;/strong&gt; in our machine and let the mongo container knows about it, in case the container dies a new one can connect to the local storage again.&lt;/p&gt;

&lt;p&gt;So lets create a directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  ~  mkdir tmp
☁  ~  cd tmp
☁  tmp  mkdir datamongodb
☁  tmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to obtain or path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  datamongodb  pwd
/Users/ernestol/tmp/datamongodb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this we can run a container with a bind mount.&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://docs.docker.com/storage/bind-mounts/" rel="noopener noreferrer"&gt;Docker Documentation&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  datamongodb  docker run -d --name mongodb01 -v /Users/ernestol/tmp/datamongodb:/data/db mongo
7d375ef665c5adfee4df4217ef9d7xxxxxxxxx41237032879a7ae99ee32d613a
☁  datamongodb  docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS       NAMES
7d375ef665c5   mongo     "docker-entrypoint.s…"   43 seconds ago   Up 42 seconds   27017/tcp   mongodb01
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; See that locally and on mongoDB Atlas we use the default port 27017 but you can change this.&lt;/p&gt;

&lt;p&gt;Let get into the container to start the mongodb database to see what happens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  datamongodb  docker exec -it mongodb01 bash

root@7d375ef665c5:/# ls /data/db
WiredTiger         WiredTigerHS.wt                       collection-4--3382512612996164992.wt  index-5--3382512612996164992.wt  sizeStorer.wt
WiredTiger.lock    _mdb_catalog.wt                       diagnostic.data                       index-6--3382512612996164992.wt  storage.bson
WiredTiger.turtle  collection-0--3382512612996164992.wt  index-1--3382512612996164992.wt       journal
WiredTiger.wt      collection-2--3382512612996164992.wt  index-3--3382512612996164992.wt       mongod.lock
root@7d375ef665c5:/# mongo
MongoDB shell version v5.0.4
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&amp;amp;gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("9c275138-c0a6-42d9-af2d-f63cac040318") }
MongoDB server version: 5.0.4
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.

        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
&amp;gt; show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
&amp;gt; use test
switched to db test

&amp;gt; db.greets.insertOne({"salute": "Hello Peter!"})
{
    "acknowledged" : true,
    "insertedId" : ObjectId("61bd1e6caecda5e2f0f2932f")
}
&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And notice that those files inside &lt;code&gt;/data/db/&lt;/code&gt; are the sale that are in our local computer and represent the database files form mongodb&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  datamongodb  ls
WiredTiger                           _mdb_catalog.wt                      diagnostic.data                      index-8--3382512612996164992.wt
WiredTiger.lock                      collection-0--3382512612996164992.wt index-1--3382512612996164992.wt      journal
WiredTiger.turtle                    collection-2--3382512612996164992.wt index-3--3382512612996164992.wt      mongod.lock
WiredTiger.wt                        collection-4--3382512612996164992.wt index-5--3382512612996164992.wt      sizeStorer.wt
WiredTigerHS.wt                      collection-7--3382512612996164992.wt index-6--3382512612996164992.wt      storage.bson
☁  datamongodb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not you can kill your containers and create others an mount those files.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;3. Create a demo replicaset using mtools&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;mtools is a collection of helper scripts to parse, filter, and visualize MongoDB log files (mongod, mongos). mtools also includes mlaunch, a utility to quickly set up complex MongoDB test environments on a local machine, and mtransfer, a tool for transferring databases between MongoDB instances.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Some of the mtools characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Written in Python. Requires Python &lt;code&gt;3.7 &amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Not officially supported by MongoDB&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Open Source&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Only command line interface.&lt;/li&gt;
&lt;li&gt;Currently being updated&lt;/li&gt;
&lt;li&gt;Tested for mongodb 4.0 or newer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can clone the corresponding &lt;a href="https://github.com/rueckstiess/mtools" rel="noopener noreferrer"&gt;repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is a bunch of good scripts and tools in this repo but the one we want to focus on is the mlaunch&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;a script to quickly spin up local test environments, including replica sets and sharded systems (requires pymongo)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This required pymongo so make sure you have installed on your local computer.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;☁  datamongodb  pip3 install pymongo&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And also you need to install the &lt;strong&gt;mtools&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The easiest way to install mtools is via pip3&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  mtools [develop] pip3 install mtools

Collecting mtools
  Downloading mtools-1.6.4-py3-none-any.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 1.9 MB/s
Collecting python-dateutil&amp;gt;=2.7
  Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (from mtools) (1.16.0)
Installing collected packages: python-dateutil, mtools

Successfully installed mtools-1.6.4 python-dateutil-2.8.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may found that some of the scripts required additional packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Traceback (most recent call last):
  File "/usr/local/bin/mlaunch", line 5, in &amp;lt;module&amp;gt;
    from mtools.mlaunch.mlaunch import main
  File "/usr/local/lib/python3.9/site-packages/mtools/mlaunch/mlaunch.py", line 20, in &amp;lt;module&amp;gt;
    import psutil
ModuleNotFoundError: No module named 'psutil'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so you may need to install requires packages&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;IMPORTANT&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;MONGOD is necessary to run this tools.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;mongod is the primary daemon process for the MongoDB system&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is differente from the &lt;strong&gt;mongo shell&lt;/strong&gt; so make sure you install also mongod with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  mtools [develop] brew tap mongodb/brew
==&amp;gt; Tapping mongodb/brew
Cloning into '/usr/local/Homebrew/Library/Taps/mongodb/homebrew-brew'...
remote: Enumerating objects: 806, done.
remote: Counting objects: 100% (303/303), done.
remote: Compressing objects: 100% (217/217), done.
remote: Total 806 (delta 153), reused 140 (delta 83), pack-reused 503
Receiving objects: 100% (806/806), 176.54 KiB | 1.26 MiB/s, done.
Resolving deltas: 100% (391/391), done.
Tapped 14 formulae (30 files, 241.7KB).

☁  bin  brew install mongodb-community@5.0
Running `brew update --preinstall`...
==&amp;gt; Downloading https://fastdl.mongodb.org/tools/db/mongodb-database-tools-macos-x86_64-100.5.1.zip
######################################################################## 100.0%
==&amp;gt; Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-5.0.4.tgz
######################################################################## 100.0%
==&amp;gt; Installing mongodb-community from mongodb/brew
==&amp;gt; Installing dependencies for mongodb/brew/mongodb-community: mongodb-database-tools
==&amp;gt; Installing mongodb/brew/mongodb-community dependency: mongodb-database-tools
🍺  /usr/local/Cellar/mongodb-database-tools/100.5.1: 13 files, 115.7MB, built in 8 seconds
==&amp;gt; Installing mongodb/brew/mongodb-community
==&amp;gt; Caveats
To start mongodb/brew/mongodb-community now and restart at login:
  brew services start mongodb/brew/mongodb-community
Or, if you don't want/need a background service you can just run:
  mongod --config /usr/local/etc/mongod.conf
==&amp;gt; Summary
🍺  /usr/local/Cellar/mongodb-community/5.0.4: 11 files, 181.4MB, built in 8 seconds
==&amp;gt; Running `brew cleanup mongodb-community`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==&amp;gt; Caveats
==&amp;gt; mongodb-community
To start mongodb/brew/mongodb-community now and restart at login:
  brew services start mongodb/brew/mongodb-community
Or, if you don't want/need a background service you can just run:
  mongod --config /usr/local/etc/mongod.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then run it by using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  data [develop] ⚡  mlaunch init --replicaset nodes 3 --name mymongo --port 3000
launching: "mongod" on port 3000
launching: "mongod" on port 3001
launching: "mongod" on port 3002
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connect using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongo --host mymongo/$(hostname):3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes this could fail because the replicaset is not starting,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You can still launch a single one&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  data [develop] ⚡  mlaunch init --single --name mymongo --port 31001 --dir ./data2
A different environment already exists at /Users/ernestolopez/tmp/datamongodb/mtools/mtools/data/data2.
☁  data [develop] ⚡  mlaunch init --single --name mymongo --port 32001 --dir ./data3
launching: "mongod" on port 32001

☁  data [develop] ⚡  ls
data2 data3
☁  data [develop] ⚡  mlaunch list --dir data3

PROCESS    PORT     STATUS     PID

single     32001    running    81184

☁  data [develop] ⚡  mongo --host localhost:32001
\MongoDB shell version v5.0.4

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>mongodb</category>
      <category>nosql</category>
      <category>development</category>
      <category>docker</category>
    </item>
    <item>
      <title>Quickops 2: Configure Python SDK for OCI</title>
      <dc:creator>Ernesto Lopez</dc:creator>
      <pubDate>Fri, 10 Dec 2021 20:24:45 +0000</pubDate>
      <link>https://dev.to/aernesto24/quickops-2-configure-oci-sdk-for-python-i4b</link>
      <guid>https://dev.to/aernesto24/quickops-2-configure-oci-sdk-for-python-i4b</guid>
      <description>&lt;p&gt;Before you can start using python SDK for OCI you need to comply with the following requirements, and also certain information you need to have at hand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Signing public and private key pair.

&lt;ul&gt;
&lt;li&gt;OCI request the key to be on PEM format. you can use the following commands
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openssl genrsa -out oci-api-key -aes128 2048
chmod go-rwx oci-api-key
openssl rsa -pubout -in oci-api-key -out oci-api-key.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; It is required that the private key has permissions only to the file owner, otherwise you will receive an error when trying to use it on OCI.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upload the public key to your user on OCI
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fls5x0xa5eo8ks5p94pk5.png" alt="Access to user OCI" width="800" height="893"&gt;

&lt;ul&gt;
&lt;li&gt;Move to Identity &amp;gt; Users &amp;gt; User Details &amp;gt; API Keys &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

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

&lt;p&gt;Clic over Add API key - Here you will paste the content from the &lt;strong&gt;oci-api-key.pub&lt;/strong&gt; file you just generated, and click over &lt;strong&gt;Add&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Take note of the fingerprint that will appear on your console. OCI use fingerprint during authentication phase to review your keys.&lt;br&gt;
Fingerprints looks something like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;56:73:ff:44:8f:b3:c3:1d:58:12:a8:1f:ff:ff:aa:66&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Take note of your user OCI&lt;/li&gt;
&lt;li&gt;Take note of the tenancy OCID
You can look it on the console &lt;strong&gt;(Menu &amp;gt; Administration &amp;gt; Tenancy Details)&lt;/strong&gt; Remember that: tenant OCID is Root Compartment OCI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can get more information about Compartments in OCID &lt;a href="https://dev.to/aernesto24/7-things-to-know-about-compartments-on-oracle-cloud-infrastructure-4l1p"&gt;HERE&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get your &lt;strong&gt;Region Identifier&lt;/strong&gt; 
This should be the region selected when the account was created, or in case you subscribed to a different region, it should be that region. Example:
&amp;gt; region=us-phoenix-1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we can proceed to the SDK configuration&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;Python SDK&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In simple words, an SDK is a library that allows a programming language to interact with Oracle cloud infrastructure resources.&lt;/p&gt;

&lt;p&gt;For this case we are using &lt;a href="https://github.com/oracle/oci-python-sdk" rel="noopener noreferrer"&gt;Python SDK&lt;/a&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;1.- So, to install the SDK, first we need to make sure we have python installed.&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; Python SDK works with both version 2 or 3 but use the latest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  .oci  python --version
Python 3.9.7
☁  .oci
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On your case you may find that the versions is pointing to python 2. To set python 3 as default on MAC yo can consult one of these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://opensource.com/article/19/5/python-3-default-mac" rel="noopener noreferrer"&gt;The right and wrong way to set Python 3 as default on a Mac&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/malwarebo/how-to-set-python3-as-a-default-python-version-on-mac-4jjf"&gt;How to set Python3 as a default python version on MacOS?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;2.- Update pip as Python SDK for OCI is a &lt;a href="https://pypi.org/project/oci/" rel="noopener noreferrer"&gt;PyPi module&lt;/a&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Under the documentation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is the Python SDK for Oracle Cloud Infrastructure. Python 3.6, 3.7, 3.8 and 3.9 are supported.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And also as a note:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is highly recommended that a Python virtual environment be used when installing oci.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let follows the recommendations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;☁  oci-sdk-python  ls
☁  oci-sdk-python  python -m venv ocisdk
☁  oci-sdk-python  ls
ocisdk
☁  oci-sdk-python  source ocisdk/bin/activate


(ocisdk) ☁  oci-sdk-python  python -m pip install --upgrade pip
Requirement already satisfied: pip in ./ocisdk/lib/python3.9/site-packages (21.2.4)
Collecting pip
  Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 1.6 MB/s
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
Successfully installed pip-21.3.1
(ocisdk) ☁  oci-sdk-python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can proceed to install OCI SDK&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(ocisdk) ☁  oci-sdk-python  pip install oci
...
Installing collected packages: pycparser, cffi, six, cryptography, pytz, python-dateutil, pyOpenSSL, circuitbreaker, certifi, oci
    Running setup.py install for circuitbreaker ... done
Successfully installed certifi-2021.10.8 cffi-1.15.0 circuitbreaker-1.3.2 cryptography-3.4.7 oci-2.52.1 pyOpenSSL-19.1.0 pycparser-2.21 python-dateutil-2.8.2 pytz-2021.3 six-1.16.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  &lt;strong&gt;3.- Create OCI Config file&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;If you remember, at the beginning i wrote some information you need to have at hand, well now is the moment to use that information.&lt;/p&gt;

&lt;p&gt;There are &lt;strong&gt;2 ways&lt;/strong&gt; to setup your config file,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FIRST&lt;/strong&gt;, by installing OCI CLI and running the setup dialog&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew update &amp;amp;&amp;amp; brew install oci-cli
oci --version

oci setup config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; More on the &lt;a href="https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SECOND&lt;/strong&gt;, by manually creating the file under &lt;code&gt;~/.oci&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd
cd .oci
vi config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and inside the config file add 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;[DEFAULT]
user = &amp;lt;user-ocid&amp;gt;
fingerprint = &amp;lt;fingerprint from your user API key &amp;gt;
tenancy = &amp;lt;tenancy-id or rootCompartment-id&amp;gt;
region = us-phoenix-1
key_file = &amp;lt;the full path to your private key file in pem format&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; the file should have the following permissions&lt;br&gt;
&lt;code&gt;-rw-------&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can store several profiles on the same file.&lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;4.- Finally!!! Using the SDK&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;If you deactivate your venv execute the source command again,&lt;br&gt;
Under the venv run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(ocisdk) ☁  oci-sdk-python  python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And inside the Python CLI run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; import oci
&amp;gt;&amp;gt;&amp;gt; config = oci.config.from_file("~/.oci/config", "DEFAULT2")
&amp;gt;&amp;gt;&amp;gt; identity = oci.identity.identityClient(config)
Traceback (most recent call last):
  File "&amp;lt;stdin&amp;gt;", line 1, in &amp;lt;module&amp;gt;
AttributeError: module 'oci.identity' has no attribute 'identityClient'
&amp;gt;&amp;gt;&amp;gt; identity = oci.identity.IdentityClient(config)
&amp;gt;&amp;gt;&amp;gt; availability_domains_list = identity.list_availability_domains(config['tenancy']).data


&amp;gt;&amp;gt;&amp;gt; for availability_domain in availability_domains_list:
...     print('AD: ' + str(availability_domain.name))
...
//look for your results
&amp;gt;&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You can find information on any known issues with the SDK here and under the “Issues” tab of this project’s &lt;a href="https://github.com/oracle/oci-python-sdk" rel="noopener noreferrer"&gt;Github Repository&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>python</category>
      <category>oraclecloud</category>
      <category>beginners</category>
      <category>sdk</category>
    </item>
  </channel>
</rss>
