AWS Compute Services Sinhala Guide | EC2, Lambda, Auto Scaling, Elastic Beanstalk

AWS Compute Services Sinhala Guide | EC2, Lambda, Auto Scaling, Elastic Beanstalk

ආයුබෝවන් යාළුවෝ හැමෝටම! 👋 අද අපි කතා කරන්න යන්නේ Cloud Computing ලෝකයේ ප්‍රබලම platform එකක් වෙන Amazon Web Services (AWS) ගැන. විශේෂයෙන්ම AWS Compute Services කියන්නේ අපේ applications run කරන්න, scale කරන්න, සහ manage කරන්න නැතුවම බැරි දේවල්. මේවා හරියට තේරුම් ගත්තොත්, ඔබට පුළුවන් ඔබේ projects වල කාර්යක්ෂමතාවය (efficiency) වැඩි කරගෙන, වියදම් අඩු කරගෙන, නියම solution එකක් develop කරන්න. අද මේ article එකෙන් අපි AWS Compute Services කිහිපයක් ගැන ගැඹුරින් කතා කරමු.

ඔබේ application එකට server එකක් අවශ්‍යද? එහෙම නැත්නම් serverless විදියට run වෙන්න ඕනෙද? නැත්නම් deploy කරන්න ලේසි platform එකක්ද? මේ හැම ප්‍රශ්නයකටම උත්තර AWS Compute Services අතර තියෙනවා. ඉතින් අපි පටන් ගමුද?

AWS EC2 – ඔබේ Virtual Servers Cloud එකේ

AWS EC2 (Elastic Compute Cloud) කියන්නේ AWS වල තියෙන core service එකක්. සරලවම කිව්වොත්, ඔබට අවශ්‍ය ඕනෑම වෙලාවක, ඔබට අවශ්‍ය configuration එකකින් Cloud එකේ virtual servers (virtual machines) හදාගන්න පුළුවන් service එකක් තමයි EC2 කියන්නේ. මේවාට අපි EC2 instances කියලා කියනවා. ඔබට අවශ්‍ය OS එක (Linux, Windows) install කරලා, ඔබට අවශ්‍ය application එක deploy කරලා වැඩේ පටන් ගන්න පුළුවන්. හරියට ඔබේ ගෙදර තියෙන desktop එකක් වගේ, හැබැයි Cloud එකේ!

EC2 Instance Types – විවිධ අවශ්‍යතා සඳහා

AWS එකේ විවිධ වර්ගයේ EC2 instances තියෙනවා, ඔබේ application එකේ අවශ්‍යතාවයට අනුව ඒවා තෝරාගන්න පුළුවන්.

  • General Purpose Instances (e.g., T, M series): මේවා බහුලවම භාවිතා වෙනවා. Web servers, development environments වගේ දේවල් වලට හොඳයි. සාමාන්‍ය CPU, memory අවශ්‍යතා තියෙන applications වලට ගැලපෙනවා.
  • Compute Optimized Instances (e.g., C series): CPU intensive applications, high-performance computing (HPC) වලට මේවා ගැලපෙනවා. Gaming servers, video encoding වගේ දේවල් වලට හොඳයි.
  • Memory Optimized Instances (e.g., R, X, Z series): විශාල දත්ත ප්‍රමාණයක් memory එකේ store කරගෙන වැඩ කරන applications (e.g., high-performance databases, real-time processing) වලට මේවා සුදුසුයි.
  • Accelerated Computing Instances (e.g., P, G, F series): මේවා GPUs (Graphics Processing Units) හෝ FPGAs (Field Programmable Gate Arrays) තියෙන instances. Machine Learning, Deep Learning, graphics rendering වගේ දේවල් වලට මේවා පාවිච්චි කරනවා.
  • Storage Optimized Instances (e.g., I, D, H series): විශාල දත්ත ප්‍රමාණයක් local storage එකේ store කරගෙන ඉහළ I/O performance එකක් අවශ්‍ය applications (e.g., NoSQL databases, data warehousing) වලට හොඳයි.

EC2 Pricing Models – සල්ලි ඉතිරි කරගන්න ක්‍රම

EC2 instances වලට සල්ලි ගෙවන්න විවිධ ක්‍රම තියෙනවා. මේවා තේරුම් ගත්තොත් ඔබට විශාල වියදමක් ඉතිරි කරගන්න පුළුවන්:

  • On-Demand Instances: මේක තමයි සරලම ක්‍රමය. ඔබ instance එකක් පටන් ගත්තාම, ඒක running වෙන හැම පැයකටම (හෝ තත්පරයකට) ගාස්තුවක් යනවා. කලින් commitment එකක් නෑ. ඔබ test කරන projects වලට, හෝ unpredictable workloads වලට මේවා හොඳයි.
  • Reserved Instances (RIs): ඔබ 1 අවුරුද්දක හෝ 3 අවුරුද්දක කාලයකට instance එකක් පාවිච්චි කරන්න commitment වෙනවා නම්, On-Demand වලට වඩා 75% ක් දක්වා වට්ටම් ගන්න පුළුවන්. Predictable workloads තියෙන applications වලට මේවා ගොඩක් හොඳයි.
  • Spot Instances: මේවා AWS වල භාවිතා නොවන EC2 capacity එක මත බිඩ් (bid) කරන්න පුළුවන් instances. On-Demand වලට වඩා 90% ක් දක්වා වට්ටම් ගන්න පුළුවන්. හැබැයි AWS වලට capacity එක අවශ්‍ය වුණොත් ඔබේ instance එක terminate වෙන්න පුළුවන්. Fault-tolerant applications, batch jobs, data processing වගේ දේවල් වලට මේවා ගොඩක් හොඳයි.
  • Savings Plans: මේවා RIs වලට සමානයි, හැබැයි තව ටිකක් flexible. පැයකට commit වෙනවා නම් (e.g., $10/hour), EC2, Fargate, Lambda වගේ services වලටත් වට්ටම් ගන්න පුළුවන්.

ප්‍රායෝගික උපදෙස: ඔබ AWS Free Tier එක පාවිච්චි කරනවා නම්, t2.micro හෝ t3.micro instance එකක් (මාසෙකට පැය 750ක්) නොමිලේ පාවිච්චි කරන්න පුළුවන්. ඒකෙන් පටන් ගන්න!

EC2 කළමනාකරණය පහසු කරන මෙවලම් – Launch Templates සහ Auto Scaling Groups

අපි EC2 instances ගැන කතා කළා. දැන් බලමු මේවා effectively manage කරන්න පුළුවන් කොහොමද කියලා.

Launch Templates – ඔබේ Instance Blueprint එක

ඔබට එකම වර්ගයේ EC2 instances ගොඩක් හදන්න අවශ්‍ය නම්, හැම වෙලාවෙම එකින් එකට settings configure කරන එක ටිකක් අමාරු වැඩක්. මෙතැනට තමයි Launch Templates එන්නේ.

Launch Template එකක් කියන්නේ EC2 instance එකක් launch කරන්න අවශ්‍ය සියලුම configuration settings අඩංගු blueprint එකක් වගේ. මේකට ඇතුළත් දේවල්:

  • AMI (Amazon Machine Image) – OS එක සහ pre-installed software එක
  • Instance Type (e.g., t2.micro, m5.large)
  • Security Groups – network access control
  • Key Pair – SSH access සඳහා
  • Storage volumes
  • User Data – instance එක පටන් ගන්නකොට run වෙන්න ඕන script (e.g., web server install කරන script)

මේවා කලින්ම template එකක හදලා තිබුණාම, අලුත් instance එකක් launch කරනකොට ඒ template එක තෝරලා විනාඩි දෙකෙන් වැඩේ කරන්න පුළුවන්. කාලය ඉතිරි වෙනවා වගේම, හැම වෙලාවෙම consistent configuration එකක් තියෙනවා. Production environments වලදී මේවා නැතුවම බැරි දෙයක්.

Auto Scaling Groups (ASG) – ස්වයංක්‍රීයව Instances Scale කිරීම

හිතන්න ඔබේ web application එකට දවසට එක එක වෙලාවට විවිධ traffic ප්‍රමාණයක් එනවා කියලා. උදේට traffic අඩුයි, හවසට වැඩියි. මේ වගේ වෙලාවක, traffic එක වැඩි වෙනකොට අලුත් instances automatically add කරලා, traffic එක අඩු වෙනකොට instances අයින් කරලා සල්ලි ඉතිරි කරගන්න පුළුවන් නම් කොච්චර හොඳද?

ඒකට තමයි Auto Scaling Groups (ASG) තියෙන්නේ. ASG එකක් කියන්නේ EC2 instances group එකක් automatically scale කරන්න (වැඩි කරන්න හෝ අඩු කරන්න) භාවිතා කරන සේවාවක්. මේකෙන් ඔබේ application එකේ High Availability එකයි, Fault Tolerance එකයි තහවුරු කරනවා වගේම, වියදම් අඩු කරගන්නත් පුළුවන්.

ASG එකක් හදනකොට, අපි දෙනවා:

  • Launch Template එකක් (උඩින් කතා කරපු එක)
  • Minimum, Maximum, සහ Desired instance count එකක්
  • Scaling Policies – මොන තත්ත්වයකදීද instances වැඩි වෙන්න හෝ අඩු වෙන්න ඕනේ කියලා (e.g., CPU utilization 70% ට වඩා වැඩි නම් අලුත් instance එකක් add කරන්න)

උදාහරණයක් විදියට, ඔබට පුළුවන් ඔබේ EC2 instances වල CPU utilization එක 70% ට වඩා වැඩි වෙනකොට තව instance එකක් add කරන්න කියලා ASG එකට කියන්න. ඒ වගේම, CPU utilization එක 30% ට වඩා අඩු වෙනකොට instance එකක් remove කරන්න කියලත් කියන්න පුළුවන්. මේකෙන් ඔබේ application එකට හැම වෙලාවෙම අවශ්‍ය compute power එක ලැබෙනවා.

මෙන්න පොඩි CLI command එකක් Auto Scaling Group එකක් update කරන විදියට:

aws autoscaling update-auto-scaling-group \
    --auto-scaling-group-name MyWebAppASG \
    --min-size 2 \
    --max-size 10 \
    --desired-capacity 4

මේ CLI command එකෙන් කියන්නේ MyWebAppASG කියන Auto Scaling Group එකේ අවම instances 2ක්, උපරිම instances 10ක් සහ දැනට instances 4ක් තිබිය යුතුයි කියලයි.

Serverless විප්ලවය – AWS Lambda

අපි මේ වෙනකම් කතා කරේ servers manage කරන එක ගැනනේ. හැබැයි, Serverless Computing කියන්නේ ඊට හාත්පසින්ම වෙනස් concept එකක්. මෙතනදී ඔබට servers manage කරන්න අවශ්‍ය වෙන්නේ නෑ. ඔබේ code එක දෙනවා, AWS ඒක run කරනවා. ගෙවන්න ඕන code එක run වෙන කාලෙට විතරයි. මේක තමයි Cloud Computing වල ලොකුම විප්ලවයක්. AWS Lambda කියන්නේ මේ Serverless concept එකේ ප්‍රමුඛයා.

AWS Lambda – Event-Driven Functions

Lambda කියන්නේ ඔබට code run කරන්න පුළුවන් compute service එකක්, servers ගැන හිතන්නේ නැතුව. මේවා event-driven. ඒ කියන්නේ, යම්කිසි event එකක් (සිද්ධියක්) වෙනකොට Lambda function එකක් run වෙනවා.

Key Concepts:

  • Functions: ඔබේ code එක Lambda function එකක් විදියට deploy කරනවා. (Node.js, Python, Java, C#, Go, Ruby වැනි භාෂා support කරනවා)
  • Triggers/Events: මොන වගේ event එකකින්ද ඔබේ function එක run වෙන්න ඕනෙ කියන එක. උදාහරණයක් විදියට: S3 bucket එකකට අලුත් file එකක් upload කරනකොට, API Gateway හරහා HTTP request එකක් එනකොට, DynamoDB table එකකට අලුත් item එකක් add වෙනකොට.
  • Concurrency: එකම වෙලාවට run වෙන්න පුළුවන් functions ගාන.
  • Memory & Timeout: එක් එක් function එකට වෙන් කරන memory ප්‍රමාණය සහ උපරිම run වෙන්න පුළුවන් කාලය.

Lambda වල වාසි:

  • Cost-Effective: ඔබේ code එක run වෙන කාලයට විතරයි ගෙවන්න ඕන. Instance එකක් 24/7 run කරන්න අවශ්‍ය වෙන්නේ නෑ.
  • Scales Automatically: කොච්චර requests ආවත්, Lambda automatically scale වෙනවා. ඔබට ඒ ගැන හිතන්න අවශ්‍ය නෑ.
  • Less Operational Overhead: Servers patch කරන එක, update කරන එක, security manage කරන එක වගේ දේවල් ගැන ඔබට හිතන්න අවශ්‍ය නෑ. AWS එක ඒ හැමදෙයක්ම බලාගන්නවා.

සරල උදාහරණයක් විදියට, ඔබට පුළුවන් S3 bucket එකකට අලුත් image එකක් upload කරනකොට, ඒ image එක resize කරලා, තව S3 bucket එකකට දාන්න Lambda function එකක් හදන්න.

මෙන්න Python වලින් ලියපු සරල Lambda function එකක්:

import json
import boto3

def lambda_handler(event, context):
    # Log the incoming event
    print("Received event: " + json.dumps(event, indent=2))

    # Example: If triggered by S3, get bucket and key name
    if 'Records' in event and event['Records'][0].get('eventSource') == 'aws:s3':
        bucket_name = event['Records'][0]['s3']['bucket']['name']
        object_key = event['Records'][0]['s3']['object']['key']
        print(f"New object '{object_key}' uploaded to bucket '{bucket_name}'")
        
        # You can add your logic here, e.g., process the S3 object
        s3 = boto3.client('s3')
        response = s3.get_object(Bucket=bucket_name, Key=object_key)
        # Read object content, process it, etc.
        print(f"Content type: {response['ContentType']}")

    return {
        'statusCode': 200,
        'body': json.dumps('Lambda function executed successfully!')
    }

මේ Python Lambda function එක S3 bucket එකකට අලුත් object එකක් upload කරනකොට run වෙන්න පුළුවන් විදියට හදලා තියෙනවා. ඒකෙන් event එක log කරනවා, bucket name එකයි object key එකයි print කරනවා. ඔබට මෙතනට image processing, data transformation වගේ දේවල් කරන්න පුළුවන්.

ඉක්මනින් Deployment කරන්න – AWS Elastic Beanstalk

ඔබට web application එකක් තියෙනවා. ඒක deploy කරන්න servers හදන්න, load balancers configure කරන්න, auto scaling set කරන්න, databases හදන්න වගේ ගොඩක් දේවල් කරන්න ඕනේ. මේ හැමදෙයක්ම තනිවම manage කරන එක ටිකක් අමාරු වැඩක්, විශේෂයෙන්ම පොඩි team එකකට.

මෙතැනට තමයි AWS Elastic Beanstalk කියන service එක එන්නේ. Elastic Beanstalk කියන්නේ Platform as a Service (PaaS) එකක්. ඒ කියන්නේ, ඔබ ඔබේ code එක දෙනවා, Elastic Beanstalk එකෙන් ඒක run කරන්න අවශ්‍ය වන සියලුම AWS resources (EC2 instances, Load Balancers, Auto Scaling Groups, RDS databases) automatically provision කරලා, configure කරලා දෙනවා.

Elastic Beanstalk වල වාසි:

  • Quick Deployment: ඔබේ code එක upload කරාම විනාඩි කිහිපයකින් application එක deploy කරන්න පුළුවන්.
  • Easy Management: Underlying infrastructure එක ගැන හිතන්න අවශ්‍ය නෑ. Patching, updates වගේ දේවල් AWS බලාගන්නවා.
  • Auto Scaling & Monitoring: Traffic එකට අනුව automatically scale වෙනවා, monitoring tools තියෙනවා.
  • Supports Multiple Platforms: Java, .NET, PHP, Node.js, Python, Ruby, Go, Docker වගේ platforms වලට සහය දක්වනවා.

Elastic Beanstalk කියන්නේ Web applications, APIs, microservices වගේ දේවල් ඉක්මනින් සහ පහසුවෙන් Cloud එකට deploy කරන්න හොඳම විකල්පයක්.

දත්ත විශාල ප්‍රමාණයක් සැකසීම – AWS Batch

සමහර වෙලාවට අපිට විශාල දත්ත ප්‍රමාණයක් (large datasets) සැකසීම, data analysis කිරීම, scientific simulations run කිරීම වගේ දේවල් කරන්න අවශ්‍ය වෙනවා. මේවා batch processing jobs කියලා හඳුන්වනවා. මේවා immediate response එකක් අවශ්‍ය දේවල් නෙවෙයි, හැබැයි ගොඩක් compute power එකක් අවශ්‍ය වෙනවා.

AWS Batch – Managed Batch Processing

AWS Batch කියන්නේ මේ වගේ batch processing jobs run කරන්න අවශ්‍ය වන compute resources (EC2 instances, Spot instances) dynamically provision කරලා, manage කරලා දෙන fully managed service එකක්. ඔබට jobs දෙනවා, Batch ඒක execute කරනවා. ඔබට servers provision කරන එක, scale කරන එක ගැන හිතන්න අවශ්‍ය නෑ.

Batch වල ප්‍රධාන components:

  • Jobs: Run කරන්න අවශ්‍ය task එක (e.g., Python script එකක්, Docker image එකක්).
  • Job Definitions: Job එක run වෙන්න අවශ්‍ය parameters (e.g., Docker image, command, memory, vCPUs).
  • Job Queues: Jobs submit කරන තැන.
  • Compute Environments: Jobs run කරන්න අවශ්‍ය වන EC2 instances (On-Demand හෝ Spot).

AWS Batch වල වාසි:

  • Scalability: කොච්චර jobs ආවත් automatically scale වෙනවා.
  • Cost-Effective: Spot instances පාවිච්චි කරලා වියදම් අඩු කරගන්න පුළුවන්.
  • Fully Managed: Infrastructure management ගැන හිතන්න අවශ්‍ය නෑ.

Financial analysis, genomic sequencing, video rendering වගේ දේවල් වලට AWS Batch කියන්නේ ඉතාම ප්‍රබල solution එකක්.

අවසන් වශයෙන්

ඉතින් යාළුවනේ, අපි මේ ලිපියෙන් AWS Cloud එකේ තියෙන ප්‍රබල Compute Services කිහිපයක් ගැන කතා කළා. සාරාංශයක් විදියට, අපි ඉගෙන ගත්තු දේවල් මෙන්න:

  • EC2 Instances: Cloud එකේ ඔබේම virtual servers, විවිධ instance types සහ pricing models (On-Demand, Reserved, Spot) තියෙනවා.
  • Launch Templates: EC2 instances හදනකොට consistent configuration එකක් තියාගන්න උදව් වෙන blueprint එකක්.
  • Auto Scaling Groups (ASG): ඔබේ application එකේ traffic එකට අනුව EC2 instances ගණන ස්වයංක්‍රීයව වෙනස් කරලා High Availability එක සහ Fault Tolerance එක තහවුරු කරනවා.
  • AWS Lambda: Serverless computing වල ප්‍රමුඛයා. Code එක run වෙන කාලයට විතරක් ගෙවනවා, servers manage කරන්න අවශ්‍ය නෑ, event-driven.
  • AWS Elastic Beanstalk: PaaS service එකක්. Web applications, APIs ඉක්මනින් deploy කරන්න, underlying infrastructure එක ගැන හිතන්නේ නැතුව.
  • AWS Batch: විශාල දත්ත ප්‍රමාණයක් batch processing කරන්න, compute resources automatically manage කරලා දෙනවා.

මේ services හරියට තේරුම් අරගෙන පාවිච්චි කරනවා නම්, ඔබට ඔබේ applications දියුණු කරන්නත්, Cloud එකෙන් උපරිම ප්‍රයෝජන ගන්නත් පුළුවන්. මේවා තමයි Cloud Engineer කෙනෙකුට, Developer කෙනෙකුට නැතුවම බැරි දැනුම.

අදම AWS Free Tier එකෙන් පටන් අරගෙන මේ services එක්ක පොඩ්ඩක් play කරලා බලන්න. තවදුරටත් ඉගෙන ගන්න, AWS Documentation කියවන්න, online tutorials බලන්න. ඔබේ අත්දැකීම්, ප්‍රශ්න පහලින් comment කරන්න! අපි තව දුරටත් මේ ගැන කතා කරමු. ඔබට සුභ දවසක්!