0% found this document useful (0 votes)
3 views13 pages

Cloud

The document outlines a series of experiments focused on using various AWS services, including AWS CloudShell, S3, DynamoDB, Lambda, API Gateway, and CloudFront. Each experiment provides step-by-step instructions for tasks such as creating and managing resources, deploying applications, and implementing serverless architectures. The document serves as a practical guide for exploring cloud computing concepts and AWS functionalities.

Uploaded by

dushanthme2905
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
3 views13 pages

Cloud

The document outlines a series of experiments focused on using various AWS services, including AWS CloudShell, S3, DynamoDB, Lambda, API Gateway, and CloudFront. Each experiment provides step-by-step instructions for tasks such as creating and managing resources, deploying applications, and implementing serverless architectures. The document serves as a practical guide for exploring cloud computing concepts and AWS functionalities.

Uploaded by

dushanthme2905
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
EXPERIMENT-O1 EXPLORING AWS CLOUDSHELL AND THE AWS CLOUD9 IDE. Objective :- Explore the features and functionality of AWS CloudShell for executing AWS CLI commands in a pre-configured cloud environment. Go to Cloudshell . Check your version Run: aws ~version This will show your version 2. List files in the current directory Run: Is If [Link] is not listed, it means the file was not created or saved correctly. 3. Create the Python script Run: nano [Link] This will open the nano text editor. 4. Write Python code Inside the nano editor, type: print("Hello from AWS CloudShell!") 5. Save and Exit nano co Press Ctrl + X (to exit). co Press ¥ (to save changes). © Press Enter (to confirm the filename). 6. Run the script Now, execute the script: python3 [Link] OUTPUT:- EXPERIMENT-02, WORKING WITH AMAZON S3ORCHESTRATING SERVERLESS FUNCTIONS WITH AWS STEP FUNCTIONS.. Working with Amazon S3 Objective: Upload and retrieve files from an $3 bucket. Steps: 1. Create an S3 Bucket: o Log in to AWS Console. © Navigate to $3 service. © Click Create bucket, give it a unique name, and select a region. o Keep settings default and click Create bucket. 2. Upload a File: © Open the newly created bucket. © Click Upload, select a file, and click Upload. 3. Retrieve the File: Click on the file you uploaded. © Copy the Object URL and open it in a browser. o If the bucket is private, adjust permissions under Bucket Policy to allow access. Check $3 Bucket Policy (If Accessing $3) To access an $3 bucket, check the bucket policy: 1. Go to S3 Console — Select the bucket. 2. Click Permissions —> Check the Bucket Policy. 3. Ensure it allows public or specific IAM access. Example Public Read Policy { "Version": "2012-10-17", "Statement": o Select the file and click Delete. © Delete the bucket by selecting it and clicking Delete bucket. Orchestrating Serverless Functions with AWS Step Functions Objective Learn how to create an AWS Step Function workflow that orchestrates two AWS Lambda functions. Step 1: Create Two AWS Lambda Functions We will create two simple Lambda functions: 1. function1 - Takes input and passes it to the next step. 2. function2 - Receives input from function and logs it. Create function! 1. Open AWS Lambda in the AWS Console. 2. Click Create function — Select Author from scratch 3. Name it funetion1. 4. Select Runtime: Python 3.x (or [Link]). 5. Use the following code: Python (function!) import json def lambda_handler(event, context): name = [Link]("name", "Guest") return {"message”: f"Hello, {name} !"} Click Deploy. Create function2 1. Repeat steps to create another Lambda function. 2. Name it function2. import json def lambda_handler(event, context): print(f"Received message: {event{'message']}") return {"status": "Processed successfully!" } Click Deploy. Step 2: Create an AWS Step Function . Open AWS Step Functions. Click Create State Machine. Choose Author with code. Select Standard type. . Replace the default JSON with this: whee "A simple Step Function workflow", "StartAt’: "InvokeFunction!", "States": { “InvokeFunction1”: { "Type": "Task", "Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:function1", "Next": "InvokeFunction2” } “InvokeFunction2”: { "Type": "Task", “Resource”: “arn:aws:lambda:REGION:ACCOUNT_ID:function:function2", “End”: true } } } Replace: + REGION with your AWS region (¢.g., us-east-1). + ACCOUNT_ID with your AWS account ID. Click Next + Name it MyStepFunction. Click Create. Step 3: Grant Step Functions Permission to Invoke Lambda 1. Open IAM — Roles 2. Find the role used by Step Functions. 3. Attach the following policy: ( "Effect": "Allow", "Action": "lambda:InvokeFunction", "Resource": [ “arn:aws:lambda:REGION: ACCOUNT_ID:function:function!", “arn:aws:lambda:REGION: ACCOUNT _ID:function:function2" ] } Save the role. Step 4: Execute the Step Function 1. Go to AWS Step Functions — Click Start Execution. 2. Provide input JSON: ( “name”: "Alice" } Click Start Execution Step 5: Verify the Output + Check Step Functions Execution History. EXPERIMENT-03 WORKING WITH AMAZON DYNAMODB Objective To create a DynamoDB table, insert items and retrieve data using the AWS Management Console and AWS CLI. Step 1: Create a DynamoDB Table 1. Go to the AWS Management Console > DynamoDB 2. Click Create table 3. Enter Table name: Students 4. Define the Primary key: o Partition key: StudentID (Number) 5. Click Create table Step 2: Insert Data into the Table Using AWS Console: 1. Goto DynamoDB - Select your Students table 2. Click Explore Table Items — Create Item 3. Add the following data: { “StudentID": 101, “Name”: "Alice", "Age": 22, “Course’ } 4. Click Save Step 3: Retrieve Data from DynamoDB Using AWS Console: 1. Go to your Students table 2. Click Explore Table Items to view all records Using AWS CLI: 1. Run the following command in AWS CLI: aws dynamodb scan --table-name Students 2. This will return all items in the Students table ‘Computer Science" Querying a Specific Record To get details of a student with StudentID = 101, use: aws dynamodb get-item --table-name Students --key '{"StudentID": (N°: "101"}}" ixperiment-04 DEVELOPING REST APIS WITH AMAZON API GATEWAY, ‘Objective :- Creating a simple REST API using Amazon API Gateway and AWS Lambda. Step 1: Create a Lambda Function 1. Goto AWS Lambda Console — Create function 2. Select Author from scratch Set the function name as: myApiLambda Runtime: Python 3.9 Execution Role: Create a new role with basic Lambda permissions Click Create function Step 2: Add Code to Lambda Function 1. Inthe Code source section, replace the default code with: import json def lambda_handler(event, context): response = { tatusCode”: 200, "body": [Link]({"message”: "Hello from API Gateway!")) } return response 2. Click Deploy. Step 3: Create an API Gateway 1. Goto AWS API Gateway Console 2. Click Create API —> REST API — Build 3. Choose New API o [Link]: MySimpleAPI © Description: Simple API for Testing © Endpoint Type: Regional 4. Click Create API Step 4: Create a Resource & Method 1. In the left panel, click Actions —+ Create Resource © Resource Name: hello © Resource Path: /hello © Click Create Resource 2. Click Actions —> Create Method © Choose GET 3. Select Integration type —- Lambda Function 4, Enter Lambda Function Name: myApiLambda 5._ Click Save —» Click OK on the permission pop-up Step 5: Deploy API 1. Click Actions — Deploy API 2. Select New Stage ‘© Stage Name: dev © Description: Development Stage 3. Click Deploy 4. Copy the Invoke URL shown on the screen, Example: huups://[Link]- tawew com/dev EXPERIMENT -05 CREATING LAMBDA FUNCTIONS USING THE AWS SDK FOR PYTH Objecti Creating Lambda Functions using the AWS SDK for Python. Procedure To build your first Python based AWS Lambda function, follow these steps: 1. Log into the AWS console and navigate to the Lambda dashboard. 2. Click the Create Function button. 3. Specify the function’s name and the Python version (Python 3.10 is recommended). 4. Edit the Python code in Amazon's embedded code editor. 5. Click Deploy and then Test to see Python Lambda function in action! Lambda [Link] import json def lambda_handler(event, context): # TODO implement print("my first AWS lambda function with python") return { ‘statusCode': 200, ‘body’: [Link]('Hello from Lambda!") } Output:- EXPERIMENT -06 MIGRATING A WEB APPLICATION TO DOCKER CONTAINERS Objective CContainerize a simple web application using Docker, allowing it to run in any environment, Prerequisites S Install Docker (Download Here) S Install Python 3 and Flask (pip install flask) 1; Create a Simple Web Application Create a new directory for your app mkaiy my-web-app &4 cd [Link]-app Create a file named app. py and add the following Python Flask code: python CopyEdit from flask import Flask lask(_name app @[Link](/) def homed): if name =="_main ‘app-run(host="[Link], port=S000) ‘Step 2: Create a Dockerfile Inthe same directory, create a file named Decker #1 (no extension) and add: # Use an official Python runtime as a parent image FROM python:3.9 # Set the working directory inthe container WORKDIR /app “ Copy the current directory contents into the container coPY 4 Install required packages RUN pip install flask 1# Make port $000 available to the world outside this container EXPOSE 5000 4 Run the application CMD ["python', “[Link]"l ‘Step 3: Build the Docker Image Run the following command in the terminal to build your Docker image: Page 17 [As per the TU Syllabus, Regulation ~2022(CBCS Scheme) CLOUD COMPUTING ~BES6O1 docker build « my-web-app ‘Step 4: Run the Docker Container After building the image, start a container using docker run -< -p 50005000 my-web-app Si Web ion Open your browser and goto: ‘np/Nocalhost:5000 Or test it using eURL in the terminal: curl hutp:/Mocalhost:5000 Expected output EXPERIMENT AMAZON CLOUDFRONT, CACHING STRATEGIES. strate how to improve application performance using Amazon ElastiCache (data wi OBJECTIVE:- De: ) and Amazon CloudFront (content caching) Apply caching to: ‘© Store frequently accessed user profile data in ElastiCache (Redis) ‘© Deliver static content through CloudFront CDN Apply basic eaching strategies (TTL, lazy loading, cache invalidation) 1. Set up the Application (Local or AWS EC2) + Deploy a simple web app (Node js, Python Flask, etc.) + Example endpoint: /ose:/123 fetches user data from an RDS or simulated database. 2, Add Amazon ElastiCache (Redis) for Data Caching. + Launch an ElastiCache Redis cluster via AWS Console. + Modify your app to: 1. Check Redis for the user data If not present, fetch from DB, store in Redis with a TTL (eg., 60 s 2 ‘onds), 3. Return result to user. def get_user_profile(user_id) ccache_key = user: (user_id) iche_key) cached = [Link]( if cached: return [Link](cached) else user = db.query_user(user_id) [Link](cache_key, 60, [Link](user)) # 60s TTL return user 3. Use Amazon CloudFront for Static Content + Upload static assets to $3 bucket. 1 CloudFront distribution for the $3 bucket 4s in your app. + Crea + Use CloudFront URL to serve asset Example: itps://[Link]/[Link]" /> Benefits: + Global edge caching + Reduced latency + Offloading traffic from origin 4, Apply Caching Strategies ‘TTL (Time to Live) = Controls how long data stays in cache. ted, Lazy Loading = Cache data only when req CLOUD COMPUTING —nCS«01 Remove outdated items from cache (e.g.,.on update). Cache Invalidation Example Cache Invalidation: def update_user_profile(user_id, [Link](user id, new data) id)") # invalidate old cache +w_data): [Link](Fuser: (use IMPLEMENTIN CLOUDFRONT FOR CACHING AND APPLICATION SECURITY, Objective To set up an Amazon CloudFront distribution infront of an $3 bucket, enabling caching and basic pplication security features like HTTPS and origin access contol 1, Create an $3 Bucket and Upload Content + Goto $3 console 4+ Create a new bucket (em + Disable public access settings + Upload a sample HTML file (eg, sndiex. nem). it~). 2. Enable Static Website Hosting (Optional for testing) 1+ InS3 bucket properties, enable Static Website Hosting + Setindex document as index. nem 3. Create a CloudFront Distribution the AWS console. Click Create Distribution, Under Origin domain, select your $3 bucket ‘Set Origin access to Origin access control (recommended): ‘© Create anew OAC, ‘© Grant access to your $3 bucket. ‘+ Choose Viewer protocol policy: Rede ‘+ Set Default root object as inex. nem + Click Create distribution, HTTP wo HTTPS, 4. Test the Distribution 4+ After deployment (takes afew minutes), copy the CloudFront domain name (e 4123abe .clovdtront-net) and access it in a browser. ‘+ You should see your [Link] file served securely via HTTPS, Bucket policy Version”: "20 Statement’ [ { Page 21 + per the VIU Syllabus, Regulation ~2022 (CICS Scheme) LOUD COMPUTING -BCSé0 ‘Sid": “Allow lovdlrontServicePrincipalReadOnly’ "Effet": “Allow”, Principal”: ( ‘Service: “cloudtrontamazo ) ‘Aetion”;"s3:GetObject” Resource”: "arnaws:s3::my-cloudfront-labl/*" ‘Condition’: ( ‘StringEquals":{ "AWS SourceAm’: “am:aws:cloudfont::84267601 8658: distribution E2KP7FKMEFGOWS" EXPERIMENT-09 ORCHESTRATING SERVERLESS FUNCTIONS WITH AWS STEP FUNCTIONS... Objective Learn how to create an AWS Step Function workflow that orchestrates two AWS Lambda functions. We will create two simple Lambda functions: 1, funct ion! - Takes input and passes it to the next step. 2. function? - Receives input from function! and logs it. Create function! Open AWS Lambda in the AWS Console. Click Create function — Select Author from scratch. Name it function1. Select Runtime: Python 3.x (or Node,js). Use the following code: Python (function!) import json def lambda_handler(event, context): name = [Link]("name”, "Guest") return {"message”: f"Hello, {name}!"} Click Deploy. ween Create function2 1. Repeat steps to create another Lambda function, 2. Name it funetion2. import json def lambda_handler(event, context): print(f"Received message: {event['message']}") return {"status": "Processed successfully!"} Click Deploy. 2: Create an AWS Step Function Open AWS Step Functions. Click Create State Machine. Choose Author with code. Select Standard type Replace the default JSON with this: wayne { “Comment”: "A simple Step Function workflow”, "StartAt”: "InvokeFunction!", "States": { vokeFunction!”: { "Type": "Task", "Resource": "arn:aws:lambda: REGION: ACCOUNT_ID:function:function "Next": "InvokeFunction2" } wokeFunction2”: | Page 24 :aws:lambda: REGION: ACCOUNT_ID:function:function2", Replace: * REGION with your AWS region (e.g., us-east-1). + ACCOUNT_ID with your AWS account ID. Click Next —> Name it MyStepFunction. Click Create. Step 3: Grant Step Functions Permission to Invoke Lambda 1. Open IAM — Roles 2. Find the role used by Step Functions. 3. Aitach the following policy: { "Effect": "Allow", lambda: InvokeFunction", “arn:aws:lambda:REGION: ACCOUNT_ID:function:function 1", “arn:aws:lambda:REGION: ACCOUNT_ID:function:function2” ] } Save the role. Step 4: Execute the Step Function 1. Goto AWS Step Functions — Click Start Execution. 2. Provide input JSON: { “name”: “Alice” } ‘Click Start Execution. Step 5: Verify the Output + Check Step Functions Execution History. Objective: Automatically deploy a basic website wher 1, Create a Simple Website Create a file named index. htm: um! CopyBiit My CUCD Site -Welcome to my website! 2. Create a Hub Repo Go to https:/[Link] Click New Repository Name it simple-cicd-site Upload the [Link] file 3. Add GitHub Actions for Deployment 1, In your repo, create folders and a file

You might also like