AWS User Group Myanmar
  • AWS User Group Myanmar
  • AWS User Group Myanmar Events History
  • AWS User Group Myanmar Upcoming Events
  • Call for Meetup Speakers
  • FAQ
  • Fundamental
    • AWS Global Infrastructure
    • A brief History of AWS
    • Cloud Computing 101
  • Compute
    • Elastic Compute Cloud (or) EC2 - Episode (1)
    • Reduce cloud compute cost with EC2 Spot Instance
    • Deploying Wordpress Website with Amazon Lightsail
    • Feel the power of Auto Scaling and Spot Instances with auto assign EIP
  • Tutorials
    • Gain free, hands-on experience with the AWS platform, products, and services
    • Using AWS Systems Manager to login EC2 instance without SSH
    • Managing private EC2 instance with Bastion Host
    • How to complete setup Kubernetes Cluster on AWS using Kops
    • Amazon EKS Cluster Provisioning
    • Infrastructure as Code with AWS CodePipeline
    • Using AWS Lambda to monitor websites
  • Internet of Things
    • IoT Rules Engine
  • Storage
    • S3 Encryption အကြောင်း တစေ့တစောင်း
    • Cloud Object Storage (aka) Amazon Simple storage service (S3)
  • Cost and Billing
    • Cost Optimization on AWS Cloud - Part 1
    • Cost Optimization on AWS Cloud - Part 2
    • Optimizing cost with AWS Graviton-based services
  • Database
    • DynamoDB - Fast and Flexible NoSQL Managed Service -Part 1
  • Security, Identity, & Compliance
  • Learn From Home
    • AWS Essentials
  • Import
Powered by GitBook
On this page

Was this helpful?

  1. Tutorials

Using AWS Lambda to monitor websites

A microservice which can be run on AWS Lambda to monitor and check websites and metric value of website status code and response time taken per request is sent to AWS CloudWatch.

PreviousInfrastructure as Code with AWS CodePipelineNextIoT Rules Engine

Last updated 4 years ago

Was this helpful?

ဒီတစ်ခေါက်မှာတော့ AWS Lambda ကိုအသုံးပြုပြီး Website Status Monitoring Service လေးတစ်ခုကို အသုံးချပုံလေးကို ပြောပြသွားမှာဖြစ်ပါတယ်။

AWS Lambda Function ကလုပ်ဆောင်ပေးမဲ့ဟာ လေးကတော့ ရိုးရိုးရှင်းရှင်းပါပဲ။ ကျွန်တော်တို့ မြင်တွေ့နေကြ Website Status Check လိုမျိုးပဲ မိမိတို့ Website ရဲ့ Response အပေါ်မူတည်ပြီး Status Code နဲ့ Time Taken တို့ကို output အနေနဲ့ပြန်ပေးမှာဖြစ်ပါတယ်။ Output ကိုမှ ကျွန်တော်တို့ အနေနဲ့ AWS ရဲ့ CloudWatch Service ဆီကို Metric အနေနဲ့ ပို့ဆောင်ပေးမှာပါ။

ထိုမှ တစ်ဆင့် ရရှိလာတဲ့ Metric Values တွေကိုကြည့်ပြီး CloudWatch Alarms တွေမှ တစ်ဆင့် AWS Simple Notification Service ( SNS ) တို့ကို ပေါင်းစပ်အသုံးပြုကာ ကျွန်တော်တို့ရဲ့ Website က အဆင်ပြေနေရဲ့လား မပြေဘူးလားဆိုတာ ကိုသိရှိအောင်ပြုလုပ်နိုင်မှာပဲဖြစ်ပါတယ်။

ဒီ ပို့စ်ရေးဖို့ အတွက် Microservice လေးကို Develop လုပ်ပေးထားတာကတော့ ပဲဖြစ်ပါတယ်။

နောက်ပြီးတော့ အသုံးပြုမဲ့ Tech Stack ကလည်းရှင်းပါတယ်။

Source Code အနေနဲ့ကတော့ Golang နဲ့ရေးထားတဲ့ monitoring service တစ်ခုဖြစ်ပါတယ်။ Local မှာပဲအသုံးပြုနိုင်သလို AWS Lambda နဲ့လည်းတွဲဖက်ပြီး အသုံးပြုနိုင်ပါတယ်။

AWS ဘက်အခြမ်းမှာ လိုအပ်တဲ့ Service ဆိုရင်တော့ -

  • AWS IAM

  • AWS Lambda

  • AWS CloudWatch

  • AWS EventBridge ( Formerly CloudWatch Event )

  • AWS Simple Notification Service ( SNS )

တို့ပဲဖြစ်ပါတယ်။

ကျွန်တော်တို့အခု ကိစ္စမှာတော့ AWS Lambda Function နဲ့တွဲပြီးအသုံးပြုပါမယ်။ အရင်ဆုံးအနေနဲ့ ကျွန်တော်တို့ Service က Lambda ပေါ်မှာ Run ပြီးတော့ CloudWatch ကို Metric Data တွေနဲ့ Log တွေ ပို့မှာဆိုတော့ Lambda ကနေ CloudWatch ကို Right Access ရှိဖို့လိုပါတယ်။ ဒီတော့ ကျွန်တော်တို့က AWS IAM Custom Policy တစ်ခုကို create လုပ်ပြီး IAM Role နဲ့တွဲပါမယ်။ ဒီနေရာမှာ AWS IAM Role ကို အသုံးပြုချင်းက မှန်ကန်တဲ့ ရွေးချယ်မှပဲဖြစ်ပါတယ်။ ဘာလို့လဲဆိုတော့ Best Practices တွေအရ ကျွန်တော်အနေနဲ့ AWS Service တွေအချင်းချင်း communicate လုပ်တဲ့နေရာမှာ access တွေလိုအပ်လာတဲ့ အခါမှာ အကောင်းဆုံးဖြစ်လို့ပါပဲ။

ဒီတော့ AWS IAM Custom Policy တစ်ခု Create လုပ်ဖို့အတွက်

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowMeticAlarmCreation",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:PutMetricAlarm",
                "cloudwatch:PutMetricData"
            ],
            "Resource": "*"
        },
        {
            "Sid": "AllowLogCollection",
            "Effect": "Allow",
            "Action": [
                "logs:PutLogEvents",
                "logs:CreateLogStream",
                "logs:CreateLogGroup"
            ],
            "Resource": "arn:aws:logs:*:*:*"
        }
    ]
}

ကိုအောင်အေးသန်း
GitHub - AungAyeThan/monitoring-serviceGitHub
Logo