You are on page 1of 30

SANJEEV AGRAWAL GLOBAL EDUCATIONAL (SAGE) UNIVERSITY, BHOPAL

Cloud Web Services


(CA21B502)
BCA- Vth Semester
ASSIGNMENT-2
Submission Deadline: 16/11/2023
Instruction: Write your assignment question in step-by-step manner and after
performing practical attach snapshot also from your AWS account only or by IAM user.
Q1.) Demonstrate Elastic beanstalk for deploying website on configured server.
Ans. Steps for the given assignment are as follows:
Launching an EC2 Instance:
1. Sign In and Navigate to the Console: Log in to your AWS Management Console.
2. Navigate to AWS Elastic Beanstalk: Search for and select the "Elastic Beanstalk"
service from the AWS Management Console.

Fig 1.1:
3. Create Application:
 Open this service and click on “Create application”. On next configure page, add
environment tier as web server environment and type any application name.
Fig 1.2:
4. Select Platform and Review:
 Select Platform as language per your need ex- Python and select sample code or
upload your code and click on next and keep everything as default.

Fig 1.3:
Fig 1.4:
 For service access: select service role as use an existing role if role already
created or select Create and use new service role and type role name and click on
next.

Fig 1.5:
 Set up network and configuring database tags and select vpc and other tags and
click on next.
Fig 1.6:
 Select instance traffic and scaling (default) and click on next.

Fig 1.7:
Fig 1.8:
 Configure updates, monitoring, select Cloud watch and click on next.

Fig 1.9:
 Review everything and click on submit, application is successfully created now
with environment.
Fig 1.10:

Fig 1.11:

Q2.) Create an IAM user and attach policy EC2 Full access to created user.
Ans. Steps for the given assignment are as follows:
1. Sign In and Navigate to the Console: Log in to your AWS Management Console.

2. Navigate to IAM: Search for and select the "IAM" service from the AWS Management

Console.
Fig 2.1:

3. Create a user:

 Click on create user.

Fig 2.2:
 Provide the name of the user and click on next.
Fig 2.3:

4. Set Permissions:
 Set the permissions and provide the EC2 full access and click on next.
 Click on create user.

Fig 2.4:
Fig 2.5:
Q3.) Create Role for EC2 start instance from IAM policy section and write a Lambda
function for start instance automatically using created role above.
Ans. Steps to Create and host a publicly accessible static website on a Windows Server 2012
instance using Amazon EC2:
1. Sign In and Navigate to the Console:
 Log in to your AWS Management Console.

2. Navigate to IAM:
 Search for and select the "IAM" (Identity and Access Management) service from the AWS
Management Console.

Fig 3.1:
3. Create an IAM Policy:
 In the IAM dashboard, click on "Policies" in the left sidebar.

 Click "Create policy."

Fig 3.2:
 Choose the service (EC2) and actions (StartInstances, StopInstances) you want to
allow.

Fig 3.3:
Fig 3.4:
 Click "Next," provide a name and description, and then create the policy.

Fig 3.5:
Fig 3.6:
4. Create IAM Role for Lambda:
 In the IAM dashboard, click on "Roles" in the left sidebar.

 Click “Create Role”.

Fig 3.7:
 Choose the service "Lambda" and attach a policy that allows starting EC2 instances.
Fig 3.8:

Fig 3.9:
 Name the role (e.g., "EC2_Role") and create the role.
Fig 3.10:

Fig 3.11:
5. Create Lambda Function:
 Navigate to AWS Lambda from the console.
Fig 3.12:
 Click "Create function."

Fig 3.13:
 Choose "Author from scratch," name your function, select the runtime (e.g., Python 3.8), and
choose the IAM role created earlier.
Fig 3.14:
 Click "Create function."

6. Add Code to Lambda Function:


 Inside the Lambda function, in the "Function code" section, you can add code to start an EC2
instance. Here's a Python example:
import boto3
region = 'us-west-1'
instances = ['i-12345cb6de4f78g9h', 'i-08ce9b2d7eccf6d26']
ec2 = boto3.client('ec2', region_name=region)

def lambda_handler(event, context):


ec2.start_instances(InstanceIds=instances)
print('started your instances: ' + str(instances))
Fig 3.15:
 In the above example, replace the region with the region you have your EC2 instance in and
mention the “instance id” of that EC2 instance you had created. Also make sure that your EC2
instance’s state is Stopped.

Fig 3.16:
7. Test the Lambda Function:
 Configure a test event for your Lambda function, providing a JSON object with an "action"
property (either "start" or "stop").

Fig 3.17:
 Test the function to see if it starts the specified EC2 instance.
Fig 3.18:
Q4. ) Write a Lambda Function to poll Simple queue message from SQS.
Ans. Steps for the given assignment are as follows:
Step 1: Create a Lambda Function:
 Sign in to the AWS Management Console.
 Navigate to Lambda and click on "Create Function."

Fig: 4.1
Fig: 4.2
 Give the function a name, set the runtime to Python 3.9 and set the Architecture to
“arm64”.

Fig: 4.3
 Under Permissions, set the Execution role to “Create a new role from AWS policy
templates”, give your role a name and set the policy template to “Amazon SQS poller
permissions”.
Fig: 4.4
 Click on “Create Function”.
 Under code, write the following code and click on “Deploy”.
import json
def lambda_handler(event, context):
print(event)

# Check if 'Records' key is present in the event


if 'Records' in event:
records = event['Records']

for record in records:


# Assuming each record has a 'body' attribute
body = record.get('body')
if body:
print(body)
else:
print("Record does not have a 'body' attribute.")
else:
print("No 'Records' key found in the event.")
Fig: 4.5
Step 2: Create a Queue:
 Navigate to “SQS” in the AWS Management Console.

Fig: 4.6
 Click "Create Queue."
Fig: 4.7
 Set the type to Standard and let the remaining set to default.

Fig: 4.8
 Click on the queue created and then “Send and receive messages”.
 Enter the message into the message body and click on “send message”.
Fig: 4.9
 The queue will have some available message now.

Fig: 4.10
Step 3: Add a trigger to Lambda function:
 Navigate to your lambda function.
 Click on “Add Trigger” and select SQS as the source.
Fig: 4.11
 Under SQS Queue, select the Queue you created earlier.

Fig: 4.12
 Click on “Add”.
 Open the queue created earlier, the messages available will be 0 now.
Fig 4.13
Q5. ) Demonstrate Simple notification service using Email service.
Ans. Steps for the given assignment are as follows:
1) Sign In and Navigate to the Console
 Log in to your AWS Management Console.
2) Navigate to Amazon SNS
 Click on "Create topic."

Fig 5.1:

Fig 5.2:
 Provide a name and display name for your topic.
Fig 5.3:
 Click "Create topic."

Fig 5.4:
3) Create Subscribers (Endpoints)
 After creating the topic, click on the topic name.
Fig 5.5:
 Under "Create subscription," select the “Email” protocol.
 Enter the endpoint details, i.e an email address.

Fig 5.6:
4) Confirm Subscriptions
 Depending on the protocol, you might need to confirm subscriptions. For
example, you might need to click a confirmation link sent to your email.
Fig 5.7:
5) Publish a Message to the Topic
 After confirming subscriptions, go back to the topic page.

Fig 5.8:
 Click "Publish message."
 Enter a subject and message for the notification.
Fig 5.9:
 Click "Publish message."

Fig 5.10:
6) Receive Notifications
 You’ll receive a notification, for email, check your inbox.
 If you're done demonstrating, you can delete the topic and unsubscribe endpoints
to avoid any further notifications.
Fig 5.11:

You might also like