DEV Community

Cover image for Navigating the Public Cloud: A Developer's Guide to Leveraging Cloud Resources
CloudRank
CloudRank

Posted on

Navigating the Public Cloud: A Developer's Guide to Leveraging Cloud Resources

In today's digital landscape, public cloud platforms have revolutionized the way developers build, deploy, and scale applications. Whether you're a seasoned cloud architect or just starting your journey into cloud computing, understanding how to effectively leverage public cloud resources can significantly enhance your development workflow and application capabilities.

Understanding Public Cloud Computing

At its core, public cloud computing refers to computing services delivered over the public internet by third-party providers who offer resources such as virtual machines, storage, applications, and development platforms on a shared infrastructure. This model eliminates the need for organizations to maintain physical data centers and hardware, instead allowing them to leverage the vast infrastructures built by cloud service providers.

The major advantages include:

  • Cost efficiency through pay-as-you-go models
  • Almost unlimited scalability to handle growth and traffic spikes
  • Enhanced flexibility to experiment with new technologies
  • Global reach without managing physical infrastructure
  • Reduced time-to-market for new initiatives

The Big Three: AWS, Azure, and GCP

While numerous cloud providers exist, three major players dominate the market:

Amazon Web Services (AWS)

As the pioneer and market leader, AWS offers the broadest and deepest service portfolio with over 200 services spanning computing, storage, databases, networking, analytics, machine learning, and more.

Microsoft Azure

With strong enterprise integration and a comprehensive service catalog, Azure excels in hybrid cloud scenarios and appeals particularly to organizations already invested in Microsoft's ecosystem.

Google Cloud Platform (GCP)

Known for its strengths in data analytics, machine learning, and container technologies, GCP leverages Google's global network infrastructure and offers powerful solutions for data-intensive applications.

Core Service Models

Public cloud services typically fall into three primary categories:

Infrastructure as a Service (IaaS)

IaaS provides virtualized computing resources over the internet, giving you virtual machines, storage, networks, and other fundamental computing resources that you can provision and manage.

Platform as a Service (PaaS)

PaaS offers development and deployment environments in the cloud, abstracting away the underlying infrastructure and providing middleware, development tools, and database management systems.

Software as a Service (SaaS)

SaaS delivers complete applications over the internet on a subscription basis, with providers managing all aspects of the application including infrastructure, platform, and application functionality.

Getting Started: Practical Examples

Let's explore some practical examples of leveraging public cloud services for common development scenarios.

Setting Up a Virtual Machine on AWS

Creating an EC2 instance using AWS CLI:

# Install AWS CLI
pip install awscli

# Configure your AWS credentials
aws configure

# Launch an EC2 instance
aws ec2 run-instances \
  --image-id ami-0c55b159cbfafe1f0 \
  --count 1 \
  --instance-type t2.micro \
  --key-name MyKeyPair \
  --security-group-ids sg-903004f8 \
  --subnet-id subnet-6e7f829e
Enter fullscreen mode Exit fullscreen mode

Deploying a Web Application on Azure

Using Azure CLI to create an App Service and deploy your application:

# Install Azure CLI
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

# Login to Azure
az login

# Create a resource group
az group create --name MyResourceGroup --location eastus

# Create an App Service plan
az appservice plan create --name MyAppServicePlan --resource-group MyResourceGroup --sku B1

# Create a web app
az webapp create --name MyWebApp --resource-group MyResourceGroup --plan MyAppServicePlan

# Deploy from a local Git repository
az webapp deployment source config-local-git --name MyWebApp --resource-group MyResourceGroup
Enter fullscreen mode Exit fullscreen mode

Setting Up a Kubernetes Cluster on GCP

Using Google Cloud SDK to create a GKE cluster:

# Install Google Cloud SDK
# Follow instructions at https://cloud.google.com/sdk/docs/install

# Initialize the SDK
gcloud init

# Create a GKE cluster
gcloud container clusters create my-cluster \
  --num-nodes=3 \
  --zone=us-central1-a

# Get credentials for kubectl
gcloud container clusters get-credentials my-cluster --zone us-central1-a

# Deploy a sample application
kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0
kubectl expose deployment hello-server --type=LoadBalancer --port=80 --target-port=8080
Enter fullscreen mode Exit fullscreen mode

Serverless Computing: The Next Evolution

Serverless computing represents an evolution beyond traditional cloud models, allowing developers to focus purely on code without managing servers.

AWS Lambda Example

Creating a simple Lambda function using Node.js:

// index.js
exports.handler = async (event) => {
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    return response;
};
Enter fullscreen mode Exit fullscreen mode

Deploying with AWS CLI:

# Create a deployment package
zip function.zip index.js

# Create a Lambda function
aws lambda create-function \
  --function-name my-function \
  --runtime nodejs14.x \
  --role arn:aws:iam::123456789012:role/lambda-ex \
  --handler index.handler \
  --zip-file fileb://function.zip
Enter fullscreen mode Exit fullscreen mode

Azure Functions Example

A simple HTTP trigger function:

// index.js
module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    const name = (req.query.name || (req.body && req.body.name));
    const responseMessage = name
        ? "Hello, " + name + ". This HTTP triggered function executed successfully."
        : "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";

    context.res = {
        // status: 200, /* Defaults to 200 */
        body: responseMessage
    };
}
Enter fullscreen mode Exit fullscreen mode

Google Cloud Functions Example

A simple HTTP function:

// index.js
exports.helloWorld = (req, res) => {
  const message = req.query.message || req.body.message || 'Hello World!';
  res.status(200).send(message);
};
Enter fullscreen mode Exit fullscreen mode

Infrastructure as Code (IaC)

Managing cloud resources through code is a best practice for maintaining consistent, reproducible environments.

Terraform Example for Multi-Cloud

# Configure AWS provider
provider "aws" {
  region = "us-west-2"
}

# Create an AWS EC2 instance
resource "aws_instance" "web_server" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
  tags = {
    Name = "WebServer"
    Environment = "Development"
  }
}

# Configure Azure provider
provider "azurerm" {
  features {}
}

# Create an Azure resource group
resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "East US"
}

# Create an Azure virtual machine
resource "azurerm_linux_virtual_machine" "example" {
  name                = "example-machine"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  size                = "Standard_F2"
  admin_username      = "adminuser"

  network_interface_ids = [
    azurerm_network_interface.example.id,
  ]

  admin_ssh_key {
    username   = "adminuser"
    public_key = file("~/.ssh/id_rsa.pub")
  }

  os_disk {
    caching              = "ReadWrite"
    storage_account_type = "Standard_LRS"
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "18.04-LTS"
    version   = "latest"
  }
}
Enter fullscreen mode Exit fullscreen mode

Database Services in the Cloud

Each major cloud provider offers managed database services that handle operational tasks like backups, patching, and scaling.

Setting Up an AWS RDS Instance

aws rds create-db-instance \
    --db-instance-identifier mydbinstance \
    --db-instance-class db.t3.micro \
    --engine mysql \
    --master-username admin \
    --master-user-password mypassword \
    --allocated-storage 20
Enter fullscreen mode Exit fullscreen mode

Connecting to the Database from Node.js

const mysql = require('mysql');

const connection = mysql.createConnection({
  host: 'mydbinstance.xxxxxxxxxx.us-west-2.rds.amazonaws.com',
  user: 'admin',
  password: 'mypassword',
  database: 'mydb'
});

connection.connect((err) => {
  if (err) {
    console.error('Error connecting to the database:', err);
    return;
  }
  console.log('Connected to the database!');

  // Run a query
  connection.query('SELECT * FROM users', (err, results) => {
    if (err) throw err;
    console.log('Users:', results);
    connection.end();
  });
});
Enter fullscreen mode Exit fullscreen mode

Cloud Storage Solutions

Cloud storage provides scalable, durable, and secure places to store your application data.

Using AWS S3 from Python

import boto3

# Initialize S3 client
s3 = boto3.client('s3')

# Create a bucket
s3.create_bucket(
    Bucket='my-unique-bucket-name',
    CreateBucketConfiguration={'LocationConstraint': 'us-west-2'}
)

# Upload a file
s3.upload_file('local-file.txt', 'my-unique-bucket-name', 'remote-file.txt')

# Download a file
s3.download_file('my-unique-bucket-name', 'remote-file.txt', 'downloaded-file.txt')

# List objects in bucket
response = s3.list_objects_v2(Bucket='my-unique-bucket-name')
for obj in response.get('Contents', []):
    print(obj['Key'])
Enter fullscreen mode Exit fullscreen mode

Using Azure Blob Storage from .NET

using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using System;
using System.IO;
using System.Threading.Tasks;

namespace AzureBlobStorageExample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Connection string from Azure Portal
            string connectionString = "DefaultEndpointsProtocol=https;AccountName=...";
            string containerName = "mycontainer";
            string blobName = "sample-blob.txt";
            string filePath = "sample-file.txt";

            // Create a BlobServiceClient
            BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);

            // Create a container
            BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);
            Console.WriteLine($"Container {containerName} created.");

            // Get a reference to the blob
            BlobClient blobClient = containerClient.GetBlobClient(blobName);

            // Upload file
            using (FileStream uploadFileStream = File.OpenRead(filePath))
            {
                await blobClient.UploadAsync(uploadFileStream, true);
            }
            Console.WriteLine($"Blob {blobName} uploaded.");

            // Download file
            BlobDownloadInfo download = await blobClient.DownloadAsync();
            using (FileStream downloadFileStream = File.OpenWrite("downloaded-" + filePath))
            {
                await download.Content.CopyToAsync(downloadFileStream);
            }
            Console.WriteLine($"Blob downloaded to 'downloaded-{filePath}'");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Securing Your Cloud Resources

Security in cloud environments follows a shared responsibility model, where the provider secures the infrastructure, but you're responsible for securing your applications, data, and access.

Setting Up IAM Roles in AWS

# Create an IAM policy
cat > policy.json << EOF
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::my-bucket/*"
        }
    ]
}
EOF

# Create the policy
aws iam create-policy \
  --policy-name MyS3AccessPolicy \
  --policy-document file://policy.json

# Create a role
aws iam create-role \
  --role-name MyAppRole \
  --assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"ec2.amazonaws.com"},"Action":"sts:AssumeRole"}]}'

# Attach the policy to the role
aws iam attach-role-policy \
  --role-name MyAppRole \
  --policy-arn arn:aws:iam::123456789012:policy/MyS3AccessPolicy
Enter fullscreen mode Exit fullscreen mode

Enabling HTTPS in Azure App Service

# Generate a certificate request
openssl req -new -newkey rsa:2048 -nodes -keyout myserver.key -out myserver.csr

# Upload the certificate to Azure
az webapp config ssl upload \
  --name MyWebApp \
  --resource-group MyResourceGroup \
  --certificate-file mycert.pfx \
  --certificate-password mypassword

# Bind the certificate to the webapp
az webapp config ssl bind \
  --name MyWebApp \
  --resource-group MyResourceGroup \
  --certificate-thumbprint THUMBPRINT_VALUE \
  --ssl-type SNI
Enter fullscreen mode Exit fullscreen mode

Cost Management Strategies

Cloud costs can quickly escalate without proper management. Here are some strategies to keep expenses under control:

  1. Right-sizing resources: Ensure your instances match your actual needs
  2. Leveraging reserved instances: Commit to usage for significant discounts
  3. Implementing auto-scaling: Scale resources up and down based on demand
  4. Setting up budgets and alerts: Be notified before costs exceed thresholds
  5. Cleaning up unused resources: Regularly audit and remove idle resources

Setting Up AWS Budget Alerts

cat > budget.json << EOF
{
    "BudgetName": "MonthlyBudget",
    "BudgetLimit": {
        "Amount": "100",
        "Unit": "USD"
    },
    "BudgetType": "COST",
    "CostFilters": {},
    "TimePeriod": {
        "Start": 1622505600,
        "End": 3706473600
    },
    "TimeUnit": "MONTHLY"
}
EOF

cat > notification.json << EOF
{
    "Notification": {
        "NotificationType": "ACTUAL",
        "ComparisonOperator": "GREATER_THAN",
        "Threshold": 80,
        "ThresholdType": "PERCENTAGE",
        "NotificationState": "ALARM"
    },
    "Subscribers": [
        {
            "SubscriptionType": "EMAIL",
            "Address": "your-email@example.com"
        }
    ]
}
EOF

aws budgets create-budget \
  --account-id 123456789012 \
  --budget file://budget.json \
  --notifications-with-subscribers file://notification.json
Enter fullscreen mode Exit fullscreen mode

Monitoring and Observability

Effective monitoring is crucial for understanding the performance, health, and usage patterns of your cloud resources.

Setting Up AWS CloudWatch Alarms

# Create a CPU utilization alarm
aws cloudwatch put-metric-alarm \
  --alarm-name cpu-utilization \
  --alarm-description "Alarm when CPU exceeds 70%" \
  --metric-name CPUUtilization \
  --namespace AWS/EC2 \
  --statistic Average \
  --period 300 \
  --threshold 70 \
  --comparison-operator GreaterThanThreshold \
  --dimensions "Name=InstanceId,Value=i-1234567890abcdef0" \
  --evaluation-periods 2 \
  --alarm-actions arn:aws:sns:us-west-2:123456789012:my-topic
Enter fullscreen mode Exit fullscreen mode

Application Insights in Azure

# Create an Application Insights resource
az monitor app-insights component create \
  --app MyAppInsights \
  --location eastus \
  --resource-group MyResourceGroup \
  --application-type web

# Get the instrumentation key
INSTRUMENTATION_KEY=$(az monitor app-insights component show \
  --app MyAppInsights \
  --resource-group MyResourceGroup \
  --query instrumentationKey \
  --output tsv)

echo "Instrumentation Key: $INSTRUMENTATION_KEY"
Enter fullscreen mode Exit fullscreen mode

Then, add the Application Insights SDK to your application. For a Node.js app:

// app.js
const appInsights = require('applicationinsights');
appInsights.setup('YOUR_INSTRUMENTATION_KEY_HERE')
    .setAutoDependencyCorrelation(true)
    .setAutoCollectRequests(true)
    .setAutoCollectPerformance(true)
    .setAutoCollectExceptions(true)
    .setAutoCollectDependencies(true)
    .setAutoCollectConsole(true)
    .setUseDiskRetryCaching(true)
    .start();

// Your application code follows...
Enter fullscreen mode Exit fullscreen mode

Cloud-Native Development Best Practices

To get the most from cloud environments, consider these best practices:

  1. Design for failure: Assume components will fail and design accordingly
  2. Embrace microservices: Build modular, independently deployable services
  3. Use managed services: Leverage platform offerings instead of reinventing wheels
  4. Automate everything: From deployment to scaling to recovery
  5. Implement CI/CD pipelines: Automate your build and deployment processes
  6. Apply infrastructure as code: Define your infrastructure through version-controlled code
  7. Design for elasticity: Build applications that can scale both up and down
  8. Implement appropriate caching: Reduce database load and improve performance
  9. Monitor comprehensively: Track performance, errors, and business metrics
  10. Optimize for cost: Regularly review and adjust your resource utilization

The Future of Public Cloud

The public cloud continues to evolve with several key trends shaping its future:

  • Edge computing bringing cloud capabilities closer to data sources and users
  • AI and machine learning becoming integrated into every layer of cloud services
  • Serverless computing expanding beyond functions to databases and entire applications
  • Industry-specific cloud solutions tailored for healthcare, finance, manufacturing, etc.
  • Sustainability initiatives focusing on green cloud operations and efficiency

Conclusion

Public cloud platforms have fundamentally changed how we develop, deploy, and scale applications. By understanding the core services, implementing best practices, and leveraging the right tools for your specific needs, you can harness the full power of cloud computing to build more resilient, scalable, and cost-effective solutions.

The cloud journey is continuous rather than a destination—requiring ongoing learning and optimization. By embracing this mindset of continuous evolution while maintaining focus on clear business outcomes, you can leverage the transformative power of public cloud computing to create innovative solutions and deliver exceptional user experiences.

For more detailed resources on cloud computing technologies and best practices, check out CloudRank's comprehensive knowledge base.

Share your experiences, challenges, and success stories in the comments below!

Top comments (2)

Collapse
 
nevodavid profile image
Nevo David

that’s a ton packed in here, pretty hype seeing all the hands-on stuff laid out - you think long-term cost creep or just complexity ends up the bigger headache?

Collapse
 
dotallio profile image
Dotallio

This breaks down so many of the core skills I needed when first getting into the cloud. Which part of the public cloud stack was the most challenging for you to master?