AWS tools that you must know before its too late | Part 2

Shobhit Srivastava
5 min readApr 16, 2023

--

“I don’t need a hard disk in my computer if I can get to the server faster… carrying around these non-connected computers is byzantine by comparison.” — Steve Jobs

Source : FreePik

AWS (Amazon Web Services) is a leading cloud computing platform that offers a wide range of scalable and reliable services for building, deploying, and managing applications in the cloud. With its robust infrastructure, cost-effective solutions, and innovative features, AWS has become a vital tool for businesses seeking to enhance their agility, reduce IT costs, and drive innovation in the digital era.

This blog is in continuation of the Part 1 posted earlier. Here we will be discussing about next 5 aws tools that everybody should know.

Amazon RDB | Source : The Hacker News

Amazon RDS: A managed relational database service that makes it easy to set up, operate, and scale a relational database. Below is an example of creating a RDS instance using AWS SDK for Python (Boto3).

import boto3

rds = boto3.client('rds')

# Create an RDS instance
rds.create_db_instance(
DBInstanceIdentifier='mydbinstance',
Engine='mysql',
MasterUsername='myuser',
MasterUserPassword='mypassword',
AllocatedStorage=20,
Tags=[
{'Key': 'Name', 'Value': 'MyDB'}
]
)
AWS CloudFront | Source : Amazon AWS Website

Amazon CloudFront: AWS CloudFront is a content delivery network (CDN) service that accelerates the distribution of your website content to users worldwide through a global network of edge locations. It helps improve the performance, security, and reliability of your web applications.

Here’s an example of how you can create a CloudFront distribution using Python and the Boto3 AWS SDK:

import boto3

# Create a CloudFront client
cloudfront = boto3.client('cloudfront')

# Create a CloudFront distribution
response = cloudfront.create_distribution(
DistributionConfig={
'CallerReference': 'my-distribution', # A unique reference for the distribution
'Aliases': {
'Quantity': 1, # Number of CNAME aliases
'Items': ['example.com'] # List of CNAME aliases
},
'DefaultRootObject': 'index.html', # Default root object for the distribution
'Origins': {
'Quantity': 1, # Number of origin servers
'Items': [
{
'Id': 'my-origin', # A unique identifier for the origin
'DomainName': 'my-bucket.s3.amazonaws.com', # Domain name of the S3 bucket serving as the origin
'S3OriginConfig': {
'OriginAccessIdentity': ''
}
}
]
},
'DefaultCacheBehavior': {
'TargetOriginId': 'my-origin', # The origin to use for the default cache behavior
'ViewerProtocolPolicy': 'allow-all', # Viewer protocol policy (e.g., 'http-only', 'https-only', 'redirect-to-https')
'AllowedMethods': {
'Quantity': 2, # Number of allowed HTTP methods
'Items': ['GET', 'HEAD'] # List of allowed HTTP methods
},
'ForwardedValues': {
'QueryString': False # Whether to forward query strings to the origin
},
'MinTTL': 0 # Minimum time-to-live (TTL) for objects in the cache
},
'Comment': 'My CloudFront Distribution', # A comment for the distribution
'PriceClass': 'PriceClass_100', # Price class (e.g., 'PriceClass_100', 'PriceClass_200', 'PriceClass_All')
'Enabled': True # Whether the distribution is enabled or not
}
)

# Get the CloudFront distribution domain name
domain_name = response['Distribution']['DomainName']
print(f'CloudFront Distribution Domain Name: {domain_name}')
AWS CloudWatch | Source : C# Corner

AWS CloudWatch: AWS CloudWatch is a monitoring service that provides insights into the performance and health of AWS resources. Code example: “Monitoring AWS Resources with CloudWatch and Python.”

import boto3

# Create a CloudWatch client
cloudwatch = boto3.client('cloudwatch')

# Get CPU utilization for an EC2 instance
response = cloudwatch.get_metric_data(
MetricDataQueries=[
{
'Id': 'm1',
'MetricStat': {
'Metric': {
'Namespace': 'AWS/EC2',
'MetricName': 'CPUUtilization',
'Dimensions': [
{
'Name': 'InstanceId',
'Value': 'i-1234567890abcdef0'
},
]
},
'Period': 300,
'Stat': 'Average',
},
'ReturnData': True,
},
],
StartTime='2023-01-01T00:00:00Z',
EndTime='2023-04-16T23:59:59Z',
)
print(response['MetricDataResults'][0]['Values'])
AWS SageMaker | Source : XenonStack

Amazon SageMaker: Amazon SageMaker is a fully managed machine learning service that makes it easy to build, train, and deploy machine learning models. Here’s an example of how you can use Amazon SageMaker in Python to create a linear regression model:

import boto3
from sagemaker import LinearLearner

# Create a SageMaker client
sagemaker = boto3.client('sagemaker')

# Create a LinearLearner estimator
estimator = LinearLearner(
role='arn:aws:iam::123456789012:role/service-role/AmazonSageMaker-ExecutionRole',
instance_count=1,
instance_type='ml.c4.xlarge',
predictor_type='regressor'
)

# Fit the estimator to training data
estimator.fit({'train': 's3://my-bucket/train.csv'})
Encrypting messages published to Amazon SNS with AWS KMS | AWS Compute Blog

Amazon SNS (Simple Notification Service) is a messaging service that enables you to send notifications to distributed applications and microservices. Here’s an example of how you can use Amazon SNS with Python:

import boto3

# Create an SNS client
sns = boto3.client('sns')

# Publish a message to an SNS topic
response = sns.publish(
TopicArn='arn:aws:sns:us-east-1:123456789012:my-topic', # ARN of the SNS topic
Message='Hello from Amazon SNS!', # Message to be published
Subject='Test Subject' # Subject of the message
)

# Print the response
print(response)

In this example, we first create an SNS client using the boto3 library, and then use the publish() method to publish a message to a specific SNS topic. The TopicArn parameter specifies the ARN (Amazon Resource Name) of the SNS topic to which the message should be published. The Message parameter specifies the content of the message to be published, and the Subject parameter specifies the subject of the message.

Note: Make sure to replace the TopicArn with the ARN of your own SNS topic in your AWS account.

These are just a few examples of the wide range of AWS tools and services available. AWS provides extensive documentation, tutorials, and sample code to help you get started with each of these tools and learn more about their capabilities. Click here for more.

That’s all from Part 2 of the AWS Series. Stay tuned for lot more exciting content.

If this article has benefitted you in anyway. Please do support me here https://www.buymeacoffee.com/shobhitsri

--

--

Shobhit Srivastava

Software Developer | My areas of interest are: Software Development, OpenSource, Startups, Innovation