Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- [DynamoDB](./software/cloud-computing/AWS/database-services/DynamoDB/README.md)
- [RDS](./software/cloud-computing/AWS/database-services/RDS/README.MD)
- [Lambda](./software/cloud-computing/AWS/Lambda/README.MD)
- [CloudWatch](./software/cloud-computing/AWS/CloudWatch/README.md)

---

Expand Down
43 changes: 43 additions & 0 deletions src/software/cloud-computing/AWS/CloudWatch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Amazon CloudWatch

<img src="../../images/cloudwatch.png" alt="cloudwatch logo" width="100"/>

## Overview

Imagine having a magical dashboard where you can see everything happening across your applications and AWS services, in real-time. That’s Amazon CloudWatch, a smart monitoring tool from AWS!

## Key Features and Benefits

- **Real-Time Insights**: Monitor metrics and logs across your entire stack.
- **Alarms & Alerts**: Stay ahead with notifications for performance issues.
- **Custom Dashboards**: Visualize key data in a way that makes sense for you.
- **Seamless Integration**: Works with AWS services like EC2, Lambda, and more.
- **Troubleshooting Made Easy**: Explore the logs to pinpoint root causes quickly.

## Create a log group in CloudWatch Logs

CloudWatch automatically creates **log groups** while receives log events from AWS services.However, you also have the flexibility to create custom log groups manually for better organization or specific use cases. Here’s how:

1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

2. In the navigation pane, choose Log groups.

3. Choose Actions, and then choose Create log group.

4. Enter a name for the log group, and then choose Create log group.

This is an example of a log group for one my lambda functions called `sign-up`

<img src="../../images/cloudwatch1.png" alt="lambda logo" width="700"/>

Every time this function is invoked, CloudWatch automatically generates and stores the corresponding logs in a `log stream` in its associated log group. These logs include details about the execution, such as invocation times, errors, and any custom logs you’ve added within the function.

## 📚 Further Reading

- **[Amazon CloudWatch Overview](https://aws.amazon.com/cloudwatch/)**
Official AWS documentation on Amazon CloudWatch, its use cases, and features.

- **[Boto3 CloudWatch Service Reference](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudwatch.html)**
Boto3 documentation for interacting with AWS CloudWatch using the AWS SDK for Python (Boto3).

- **[Working with log groups and log streams](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html)**
62 changes: 59 additions & 3 deletions src/software/cloud-computing/AWS/Lambda/README.MD
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# AWS Lambda

<img src="../../images/lambda.png" alt="lambda logo" width="200"/>
<img src="../../images/lambda.png" alt="lambda logo" width="100"/>

## Overview

AWS Lambda is a serverless compute service that allows you to run code in response to events without managing servers. Simply upload your function code, and Lambda handles the patching, and infrastructure management.
AWS Lambda is a serverless compute service that allows you to run code in response to events without managing servers. Simply upload your function code, and Lambda takes care of the rest.

## Functions

Expand Down Expand Up @@ -33,7 +33,63 @@ In this example, the `boto3` library is used, which is the AWS SDK (Software Dev

## Creating a Lambda Function

To create a Lambda function, you need a deployment package. The deployment package is a .zip file archive or container image that contains your function code and any external libraries used in the code. However, you do not need to include `boto3` in the dependencies, since it is already included in the AWS Lambda Python runtime environment.
To create a Lambda function, you need a deployment package. The deployment package is a .zip file archive or container image that contains your function code and any external libraries used in the code.

### Steps to Create the `.zip` File

1. **Save your Python code in a file, for example, `lambda_function.py`.**
2. **Install Dependencies**
If your function has external dependencies, list them in a `requirements.txt` file. To generate `requirements.txt` from an existing project, run:

```bash
pip freeze > requirements.txt
```

`Note`: Exclude boto3 from the file to reduce the package size, since it is already included in the AWS Lambda Python runtime environment.

```bash
pip uninstall boto3 -y
```

3. **Install Dependencies Locally**
Create a directory for your function and install the dependencies into that directory:

```bash
mkdir my-lambda-function
pip install -r requirements.txt -t my-lambda-function/
```

4. **Add Your Function Code**
Copy your lambda_function.py file into the same directory:

```bash
cp lambda_function.py my-lambda-function/
```

5. **Create the .zip File**
Package the directory into a .zip file:

```bash
cd my-lambda-function
zip -r ../my-lambda-function.zip .
cd ..
```

### What's Next?

There are multiple ways to create your Lambda function once the package is ready, including:

1. **Manually via the AWS Console**: Upload the `.zip` file directly through the AWS Management Console.
2. **AWS Command Line Interface (CLI)**: Use CLI commands to create and deploy your Lambda function.
3. **Infrastructure as Code (IaC) Tools**: Automate the creation of Lambda functions using tools like Terraform, AWS CloudFormation.

### Why Avoid Manual Deployments via the Console?

While the AWS Console provides a simple and intaractive interface for creating Lambda functions, it is **not recommended** for production deployments due to the following reasons:

- **Role Attachments**: Each Lambda function requires an IAM role with appropriate permissions. Configuring roles manually in the console can lead to errors or inconsistent configurations.
- **Reproducibility**: Deploying via the console lacks automation and version control, making it difficult to reproduce configurations across environments.
- **Scalability**: IaC tools simplify managing multiple Lambda functions and their dependencies.

## Installing boto3

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Amazon DynamoDB

<img src="../../../images/dynamodb.png" alt="dynamodb logo" width="100"/>

## Overview

Amazon DynamoDB is a fully managed NoSQL database service that provides single-digit millisecond response times, making it ideal for high-traffic applications. DynamoDB supports both key-value and document data models, allowing for flexible and dynamic data structures.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Amazon Relational Database Service (RDS)

<img src="../../../images/rds.png" alt="rds logo" width="100"/>

## Overview

Amazon RDS (Relational Database Service) is a fully managed service that simplifies the setup, operation, and scaling of relational databases in the cloud. RDS supports popular database engines, enabling users to choose the one that best fits their application’s needs.
Expand Down
136 changes: 136 additions & 0 deletions src/software/cloud-computing/Terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Terraform

<img src="../images/terraform.png" alt="terraform logo" width="100"/>

## Overview

Previously, we mentioned the benefits of using Infrastructure as Code (IaC) for creating and deploying your Lambda functions. One powerful solution for managing IaC is **Terraform**!

Terraform, developed by HashiCorp, is an open-source tool that enables you to define and provision infrastructure using a simple, human-readable configuration language. With Terraform, you can manage everything from cloud providers like AWS, Azure, and Google Cloud to on-premise resources and even SaaS integrations.

## Why Choose Terraform?

- **Declarative Configuration**: Focus on _what_ you want to achieve, and Terraform handles the _how_.
- **Version Control**: Treat infrastructure as code, keeping a record of changes alongside your application code.
- **Automation**: Reduce manual work by automating resource provisioning and updates.
- **State Management**: Terraform keeps track of your infrastructure's state, ensuring changes are safely applied.

## The Terraform Workflow

1. **Write**: Define your infrastructure using configuration files written in HCL (HashiCorp Configuration Language).
2. **Plan**: Preview the changes Terraform will make, ensuring predictability before execution.
3. **Apply**: Execute the changes to create, update, or destroy resources as specified in your configuration.
4. **Destroy**: Safely decommission resources when they're no longer required.

## Most Common Terraform Commands

Here are some of the most frequently used Terraform commands to get you started:

### Initialization

- `terraform init`: Prepares the working directory for other commands by downloading plugins and providers.

### Planning and Applying

- `terraform plan`: Generates an execution plan, showing what changes will be made to your infrastructure.
- `terraform apply`: Applies the changes required to reach the desired state defined in your configuration.

### State Management

- `terraform show`: Displays information about the Terraform state.
- `terraform state list`: Lists all resources in the current state.

### Resource Management

- `terraform validate`: Checks the syntax of your configuration files for errors.
- `terraform fmt`: Formats your configuration files to follow Terraform’s style conventions.

### Destroying Resources

- `terraform destroy`: Removes all infrastructure defined in your Terraform configuration.

## Getting Started with Terraform

Terraform has a user-friendly [documentation](https://developer.hashicorp.com/terraform/tutorials/aws-get-started?product_intent=terraform) that can guide you step-by-step on how to start with AWS.

Here is an exmaple `main.tf` on how to deploy an AWS Lambda function from **[spacelift](https://spacelift.io/blog/terraform-aws-lambda)**

```bash
provider "aws" {
region = "ca-central-1"
}
resource "aws_iam_role" "lambda_role" {
name = "Spacelift_Test_Lambda_Function_Role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_policy" "iam_policy_for_lambda" {

name = "aws_iam_policy_for_terraform_aws_lambda_role"
path = "/"
description = "AWS IAM Policy for managing aws lambda role"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
}
EOF
}

resource "aws_iam_role_policy_attachment" "attach_iam_policy_to_iam_role" {
role = aws_iam_role.lambda_role.name
policy_arn = aws_iam_policy.iam_policy_for_lambda.arn
}

data "archive_file" "zip_the_python_code" {
type = "zip"
source_dir = "${path.module}/python/"
output_path = "${path.module}/python/hello-python.zip"
}

resource "aws_lambda_function" "terraform_lambda_func" {
filename = "${path.module}/python/hello-python.zip"
function_name = "Spacelift_Test_Lambda_Function"
role = aws_iam_role.lambda_role.arn
handler = "index.lambda_handler"
runtime = "python3.9"
depends_on = [aws_iam_role_policy_attachment.attach_iam_policy_to_iam_role]
}
```

## 📚 Further Reading

- **[Download Terraform](https://www.terraform.io/)**
Get the latest version of Terraform..

- **[Terraform Documentation](https://developer.hashicorp.com/terraform)**
Official HashiCorp Terraform documentation, including tutorials and examples.

- **[Getting Started with Terraform on AWS](https://developer.hashicorp.com/terraform/tutorials/aws-get-started?product_intent=terraform)**
A step-by-step tutorial to set up and manage AWS infrastructure using Terraform.

- **[Terraform Cheat Sheet](https://github.com/scraly/terraform-cheat-sheet/blob/master/terraform-cheat-sheet.pdf)**
A handy PDF reference with Terraform commands and concepts.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/software/cloud-computing/images/dynamodb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/software/cloud-computing/images/rds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.