Ravindra BagaleCourses & study guides मराठी Track your progress

Deploy a Website to AWS EC2 Using an AI Coding Agent

Until now we wrote every page by hand: open nano on the server, type or paste, save, repeat. Now an AI coding agent does that work. We launch the EC2 server ourselves, describe the website in plain words, and the agent writes the whole project on our computer, previews it, and deploys it to the server: it logs in with our key, installs Nginx and copies the files. We also look at where these AI tools come from, what "parameters" and "tokens" mean, and the safety rules to follow when an agent touches a server.

What you'll learn in this class

  • Why an agent beats copy-paste from a chat for real projects
  • Two ways to work with an agent: a code editor with an AI extension, or the AI company's desktop app
  • A quick map of popular AI assistants
  • Open-weight models on your computer vs cloud models; parameters and tokens in plain words
  • Launching an EC2 server ready for a website (SSH, HTTP, HTTPS)
  • Installing the right extension and avoiding look-alikes
  • Writing a prompt for a website and previewing it locally
  • Asking the agent to deploy to EC2, and what it does on the server
  • Asking for changes and getting them redeployed
  • Safety rules: key path not key contents, read before you approve, no secrets in prompts, terminate test servers

1. Why: from copy-paste to an agent

The old way. You ask a chat in the browser for code, copy the answer, ssh to the server, open sudo nano index.html, paste and save.

Classroom line

Right now we use ChatGPT (in the browser).

That works for one page. A real project has hundreds or thousands of files, several languages, maybe a database. Copying each file by hand is slow, and one missed file breaks the site.

The new way. An AI coding agent works on your computer. It creates the folders and files itself, runs commands, and, once you give it the server details, uploads the project to the server.

Classroom line

Just launch the server; give everything else as a prompt.

Then and now: copy-paste by hand, or let an agentdo the work Old way: one file at a time 1. Ask a chat in the browser for code 2. Copy the answer 3. ssh to the EC2 server 4. sudo nano index.html 5. Paste, save, repeat for every file Fine for one page, painful for a real project with many files andlanguages. Agent way: the whole project 1. Launch the EC2 server yourself 2. Describe the website in a prompt 3. The agent writes all the files 4. Give IP, key file path, username 5. The agent deploys it to EC2 Changes? Ask again: it edits and redeploys.

Figure 1. Old way: chat, copy, ssh, nano, paste, for every file. Agent way: describe the site, the agent writes all the files and deploys them.

Example 1. Suppose we are building the landing page for a quick-commerce app that delivers groceries in 10 minutes. By hand that's an HTML file, a CSS file, a JavaScript file and several images, each copied separately. With an agent it's one prompt, and the agent gives you complete, ready-to-run code instead of short sample snippets.

2. What: the tools

A code editor with an AI extension, or a desktop app

A code editor is a program for writing code: VS Code is the most common; Visual Studio, Eclipse and Jupyter are others. An extension (also called a plugin or add-on) adds a feature to the editor. An AI extension adds a chat panel inside the editor, and the agent in that panel can work on the folder you opened.

The other way is the AI company's own desktop app, for example the Codex app from OpenAI. It does the same job in its own window.

Two ways to work with a coding agent A. Code editor + AI extension VS Code with an extension (add-on) from the Extensions view. The chat sits inside the editor. B. The AI company desktop app For example the Codex app, installed like any other program. Same chat, same agent, own window. Either way the agent can: create folders and files in your project folder on yourcomputer, run commands, and upload the project to your server when yougive it the details.

Figure 2. A: VS Code with an AI extension. B: the AI company's desktop app. Either way the agent creates files, runs commands and uploads the project.

A quick map of AI assistants

Many companies make AI assistants, and most of them can write code:

  1. OpenAI: ChatGPT and Codex.
  2. Anthropic: Claude, very popular for coding.
  3. xAI: Grok.
  4. Google: Gemini.
  5. Perplexity.
  6. GitHub (Microsoft): GitHub Copilot.
  7. AWS: Amazon Q, which helps with AWS questions and troubleshooting.

Cursor is different: it's an AI code editor built from VS Code, so the AI is part of the editor itself.

A quick map of popular AI assistants Company Assistant OpenAI ChatGPT, Codex Anthropic Claude xAI Grok Google Gemini Perplexity Perplexity GitHub (Microsoft) GitHub Copilot AWS Amazon Q Cursor An AI code editor built from VS Code: the AI is part of the editoritself. They all write code Some are popular for coding, Amazon Q helps with AWS questions andtroubleshooting. The steps in this chapter are similar.

Figure 3. Popular AI assistants by company, and Cursor as an AI code editor built from VS Code.

Where the model runs: your computer or the cloud

Open-weight models, for example DeepSeek or Llama, can be downloaded and run on your own computer. Their size is counted in parameters: the numbers the model learned during training, counted in billions. Small models run in a few GB of memory. Bigger ones need much more memory and a strong graphics card (GPU); NVIDIA GPUs are the most common choice. Macs with a lot of memory also run them well.

Cloud models run on the AI company's huge server farms, and you use them over the internet. They're far more capable than anything that fits on a laptop. Usage is counted in tokens: the small pieces of words the model reads and writes. Free tiers are limited; paid plans give more.

Where the model runs: your computer or the cloud Open-weight model on your computer Download and run it yourself, for example DeepSeek or Llama. Size is counted in parameters (billions). Small ones run in a few GB ofmemory. Bigger ones need much more memory and a strong GPU;NVIDIA is the common choice. Cloud model Runs on huge server farms of the AI company; you use it overthe internet. Far more capable than what fits on a laptop. Usage is counted intokens. The free tier is limited; paid plans give more. Parameters: the numbers a model learned during training. Moreparameters = bigger model. Tokens: the small pieces of words a model reads and writes.

Figure 4. Open-weight models on your computer vs cloud models; parameters and tokens in plain words.

3. How: launch the server

Step 1. In the EC2 console, click Launch instance. Pick a region, for example N. Virginia.

Step 2. Name it, for example my Web Server. Choose Amazon Linux 2023 and a small instance type such as t2.micro.

Step 3. Pick your existing key pair, for example mykey.pem. Remember where the file is on your computer: for example the Downloads folder.

Step 4. Under Network settings, keep Auto-assign public IP enabled and create a new Security Group that allows SSH (22), HTTP (80) and HTTPS (443).

Step 5. Click Launch instance. When it's running, copy its Public IPv4 address; in this chapter it's written PUBLIC_IP.

You don't install anything on the server yourself. The agent will do it.

4. How: set up the agent

Step 1. Make an empty folder for the project, for example quickshop on your Desktop.

Classroom line

Let's get to work and make a folder here. Make a folder for our project.

Step 2. Open VS Code and choose File > Open Folder, then pick quickshop.

Step 3. Click the Extensions icon in the left bar: the one that looks like four small boxes.

Classroom line

Now go to extensions... the menu with the boxes that you see here is what we call Extensions.

Step 4. Search for codex. Install Codex – OpenAI's coding agent, the one whose publisher is OpenAI with the blue verified tick.

VS Code Extensions search results for codex: the first result is Codex – OpenAI's coding agent, publisher OpenAI with a blue verified tick and an Install button; below it another extension also named Codex from a different publisher.

Whiteboard: The right extension: Codex by OpenAI with the blue verified tick. Just below it is another extension with the same name from a different publisher.

Why the tick matters. Many extensions use the same name. A fake one can read your files and steal your data. Check the publisher name and the verified tick before you click Install.

Classroom line

You see this blue tick and OpenAI; install this one only, okay.

Classroom line

Lots of them show up with the name Codex. The others could be people who steal data.

Step 5. Open the new panel and sign in when it asks.

The desktop app instead. Download the app from the AI company's official website, install it like any other program, sign in, and choose the quickshop folder as the project. The rest of the steps are the same.

5. How: ask for the website

Step 1. Pick the model setting. Agents usually let you choose between faster and smarter. Faster answers quickly and suits small tasks; smarter thinks longer and suits big projects.

Step 2. Type the prompt. Say what the site is for, what you want first, and how it should look.

Example 2: the prompt.

I want to create a website for my quick commerce app, in which I deliver
products within 10 minutes. First I want only a static website.
Create this static website for me. It must look glamorous.

Step 3. Wait while it works. The agent plans the page, then writes the files into your project folder: index.html, a stylesheet, a script and images.

Step 4. Preview it on your computer: double-click index.html to open it in the browser. In VS Code you can also use a preview extension such as Live Server, which opens it at http://127.0.0.1:5500.

Agent chat on the left with the prompt about a glamorous static website for a 10-minute quick commerce app, then a summary: a glamorous, responsive static landing page with hero messaging, delivery-address interaction, product categories, delivery flow, testimonials, animated elements and mobile responsiveness. On the right a browser preview of the page: a free delivery banner, a dash logo with a Get the app button, and the heading Need it now? We're on it.

Whiteboard: Left: the quick-commerce prompt and the agent's summary of what it built. Right: the landing page it made, previewed on the computer before deploying.

What it built in one go: a hero section, a delivery-address box, product categories, the delivery steps, testimonials, animations, and a layout that works on phones.

6. How: ask it to deploy to EC2

Step 1. Just asking "deploy to EC2" isn't enough: the agent doesn't know which server. Give it three things:

  1. The server's public IP.
  2. The path of the key file (not its contents).
  3. The username: ec2-user for Amazon Linux, ubuntu for Ubuntu.

Example 3: the deploy prompt.

PUBLIC_IP is my EC2 IP. The key pair file is in my Downloads folder,
named mykey.pem. The username is ec2-user. Deploy this website to EC2.

Step 2. Watch what it runs. First it tests the connection:

ssh -o BatchMode=yes -o ConnectTimeout=10 -i "C:\Users\you\Downloads\mykey.pem" ec2-user@PUBLIC_IP

BatchMode=yes means "never stop to ask a question", and ConnectTimeout=10 means "give up after 10 seconds if the server doesn't answer".

Step 3. It finds no web server, so it installs and starts Nginx, the same way you did by hand:

sudo yum install nginx -y
sudo service nginx start

Step 4. It copies the project files into Nginx's web root, /usr/share/nginx/html.

Step 5. Open http://PUBLIC_IP/ in your browser. The landing page is live.

What the agent does when you say: deploy to EC2 1. Connect It logs in with the key file you pointed to and the username. ssh -i "C:\Users\you\Downloads\mykey.pem"ec2-user@PUBLIC_IP 2. Web server No web server found, so it installs and starts Nginx. sudo yum install nginx -y ; sudo service nginxstart 3. Copy files It copies the project files into the Nginx web root. index.html, CSS, JS, images  ->/usr/share/nginx/html 4. Live Open it in the browser: the website is live. http://PUBLIC_IP/

Figure 5. Animation: connect with the key file path and username, install and start Nginx, copy the files to the web root, open http://PUBLIC_IP/.

If the connection fails with time errors. Check your computer's clock. Secure connections and AWS requests check the time, so a clock that is far off makes them fail. Turn on automatic date and time, then ask the agent to try again.

Classroom line

Got how to do it? Add the plugin in VS Code and tell it to deploy to EC2: give the IP, give the key pair file and tell the username, and it gets uploaded.

7. How: ask for a change

Example 4. You want different colours. In the same chat:

Change the colour scheme. Use pink and its shades.

The agent edits the stylesheet, copies the changed files to the server again, and you refresh http://PUBLIC_IP/ to see the pink version. You never opened nano.

Want a change? Ask, and the agent edits andredeploys 1. You ask A plain-language request in the same chat. change the colour scheme, use pink and its shades 2. Agent edits It changes only the files that need to change. styles.css: new pink colours 3. Redeploy, refresh It copies the changed files to the server; refresh and the newcolours show. copy again -> refresh http://PUBLIC_IP/

Figure 6. Animation: ask in plain words, the agent edits only what needs to change, redeploys, and a refresh shows the new colours.

8. Safety when an agent touches your server

An agent runs real commands with your key. Four rules:

  1. Give the key file's path, never its contents. Say "mykey.pem is in my Downloads folder". Never paste what's inside a .pem file into any chat.
  2. Read what it plans to run. Most agents ask before running a command. Approve only what you understand.
  3. No passwords or secrets in prompts. Prompts leave your computer. Keep passwords, keys and tokens out.
  4. Terminate test servers. When practice is over, terminate the instance so it stops costing money.
Four safety rules when an agent touches yourserver Give the key file path, never its contents Say where mykey.pem is. Never paste what is inside it into a chat. Read what it plans to run Approve a command only when you understand what it does on yourserver. No passwords or secrets in prompts Prompts leave your computer. Keep passwords, keys and tokens out. Terminate test servers When the practice is over, terminate the instance so it stops costing.

Figure 7. Key path not contents, read before you approve, no secrets in prompts, terminate test servers.

9. What's next

Real projects live on GitHub, where developers keep their code. Next, we host a project straight from GitHub on our server.

10. The whole flow on one page

  1. Launch Amazon Linux EC2 with SSH, HTTP and HTTPS allowed; note PUBLIC_IP.
  2. Make an empty project folder and open it in VS Code (or the desktop app).
  3. Install the verified extension: publisher OpenAI, blue tick.
  4. Pick faster or smarter, and describe the website in a prompt.
  5. Preview index.html on your computer.
  6. Ask it to deploy: IP, key file path, username.
  7. The agent connects with ssh -i, installs Nginx and copies the files to /usr/share/nginx/html.
  8. Open http://PUBLIC_IP/. Ask for changes; it redeploys.
  9. Follow the safety rules and terminate the server when done.

11. Try at home

Try at home

Task 1: build it

  1. Make a folder and open it in VS Code. Install the verified Codex extension (publisher OpenAI, blue tick).
  2. Suppose we are making the website for a food delivery app. Write a prompt for a static landing page and preview index.html.

Task 2: deploy it

  1. Launch an Amazon Linux server with SSH, HTTP and HTTPS allowed.
  2. Give the agent the IP, the key file path and ec2-user, and ask it to deploy.
  3. Read each command before you approve it, then open http://PUBLIC_IP/.

Task 3: change it

  1. Ask for a different colour scheme and check that the live site changes.

When you're done, terminate the instance.

Recap

In short

  1. Copy-paste from a chat works for one page; an agent writes and deploys a whole project.
  2. Use a code editor with an AI extension, or the AI company's desktop app.
  3. Install only the verified extension from the real publisher; look-alikes can steal data.
  4. Open-weight models run on your computer (size in parameters); cloud models are far more capable and are counted in tokens.
  5. Launch the server yourself; let the agent write the site; preview locally.
  6. To deploy, give the IP, the key file path and the username. The agent connects with ssh, installs Nginx and copies the files.
  7. Ask for changes in plain words; it redeploys.
  8. Key path not contents, read before approving, no secrets in prompts, terminate test servers.

Ravindra Bagale, trainer: linkedin.com/in/ravindra-bagale. The folder quickshop, the key name mykey.pem, the path C:\Users\you\Downloads and the prompts are examples for learning; PUBLIC_IP stands for your instance's public IPv4 address. The agent chooses its own commands, so yours may differ from the ones shown.

Practice Tasks

About this scenario

Sydney Surf School is a sports training business in Sydney. Liam O'Brien looks after its IT and cloud work. They count money in AUD and run their AWS resources in the ap-southeast-2 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 12

Easy Download code from GitHub

Why: git clone copies the whole repository to the server, ready to deploy.

What to do: Clone https://github.com/sydneysurf/website.git into the current folder.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Install a package on Ubuntu

Why: Ubuntu uses apt. Package names differ: on Ubuntu Apache is apache2.

What to do: Install the apache2 package on Ubuntu without being asked to confirm.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Test a website from the server

Why: curl shows whether the web server answers, even before DNS is ready.

What to do: Request http://localhost and show only the response headers.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Install a package on Amazon Linux

Why: dnf is the package manager on Amazon Linux 2023. -y answers yes for you.

What to do: Install the httpd package on Amazon Linux 2023 without being asked to confirm.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Restart a service after a change

Why: Config changes only apply after the service restarts or reloads.

What to do: Restart the nginx service.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Check if a service is running

Why: When a site is down, first check whether the web server process is running.

What to do: Show the status of the httpd service.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Port for SSH

Why: Security group rules need the right port.

What to do: Which TCP port must the security group open for SSH?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Test the nginx config

Why: A test catches typos before a restart takes your site down.

What to do: Check the nginx configuration files for errors.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Upload a file to the server

Why: scp copies files over SSH, so it uses the same key and user.

What to do: Upload index.html from your laptop to /home/ec2-user/ on 13.143.20.5 using sydneysurf-key.pem.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Open port 80 to the world

Why: Visitors can reach your website only if the security group allows HTTP.

What to do: Allow inbound TCP port 80 from 0.0.0.0/0 on security group sg-00ac0b505a064c3b2.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Start a service now and at boot

Why: enable makes it start after reboot; --now also starts it right away.

What to do: Enable the nginx service and start it immediately, in one command.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Block other Regions (SCP style)

Why: Data rules (like keeping data in one country) are enforced with aws:RequestedRegion.

What to do: Deny ec2:* on * when aws:RequestedRegion is not ap-southeast-2.

How:
  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: What is an AI coding agent?. A real site has many files. Copy-paste from a chat into nano for each file is slow and error-prone. An AI coding agent works on your computer: it writes files, runs commands and can deploy them. Install it as an editor extension or desktop app, describe the site in a prompt, read and approve its steps. "Build a landing page for a 10-minute grocery app and deploy it to my EC2 at 13.2.1.9."
Revision card: What is an AI coding agent? · Download PNG
Revision card: Tokens and parameters in AI models. Model names and prices use these two words. Without them you cannot compare models. Parameters = numbers the model learned (its size). Tokens = small pieces of text it reads and writes. Bigger models need more RAM. Cloud models charge per token used. An 8B model has 8 billion parameters. "Hello world" is about 2-3 tokens.
Revision card: Tokens and parameters in AI models · Download PNG
Revision card: Launch EC2 ready for a website. The agent can deploy only if the server is reachable and the web ports are open. A web-ready EC2 has a key pair and a security group allowing SSH 22, HTTP 80 and HTTPS 443. Launch, tick the three rules, then give the agent the public IP and the key PATH. Prompt detail:
Revision card: Launch EC2 ready for a website · Download PNG
Revision card: Safety rules for AI agents. An agent runs real commands on real servers. One wrong approve can delete data or leak a key. Rules: give the key path not its contents, read each command before approving, no passwords in prompts. After practice, terminate test servers so they do not cost money. Agent asks to run rm -rf /var/www. Stop and check before you approve.
Revision card: Safety rules for AI agents · Download PNG
Comparison: AI chat in a browser vs AI coding agent. AI chat in a browser: A chat that answers with text and code to copy. AI coding agent: A tool on your computer that writes files and runs commands.
Comparison: AI chat in a browser vs AI coding agent · Download PNG
Comparison: Open-weight model on your PC vs Cloud AI model. Open-weight model on your PC: A model you download and run on your own computer. Cloud AI model: A model that runs on the AI company's servers.
Comparison: Open-weight model on your PC vs Cloud AI model · Download PNG
Comparison: Editor extension vs Desktop app. Editor extension: An AI agent added inside a code editor like VS Code. Desktop app: The AI company's own app installed on your computer.
Comparison: Editor extension vs Desktop app · Download PNG
Interview card: What is the difference between an AI chat and an AI coding agent?. A chat only answers with text. An agent writes files and runs commands on your computer. Projects have hundreds of files; copying each answer by hand is slow and misses files. Agent: one prompt builds the folder, previews it and deploys to EC2.
Interview card: What is the difference between an AI chat and an AI coding agent? · Download PNG
Interview card: What should you never put in a prompt to an AI agent?. Secrets: passwords, AWS access keys or the contents of a .pem file. Prompts may be stored or logged by the provider; a leaked key gives full access. Give only the path; the agent reads the key locally.
Interview card: What should you never put in a prompt to an AI agent? · Download PNG
Interview card: When would you run an open-weight model on your own computer?. When code must stay private or you want no per-token bill. Nothing leaves your machine, but you need enough RAM or GPU. An 8B model needs about 8 GB RAM; big cloud models stay smarter.
Interview card: When would you run an open-weight model on your own computer? · Download PNG

More cards: Ravi Sir's Cards.