[AWS] Lab: Lambda - build a Chaos monkey
Solution Outline
To run our function we use a service called CloudWatch, which periodically generates events. Those events are sent to the Lambda function, and on each event, the Lambda function gets a list of instances from the environment and will randomly terminate one of them. (see below the summary diagram)
You can find the code for this demo in the course repo: https://github.com/udacity/cloud-developer/tree/master/course-04/exercises/c4-demos-master/04-chaos-monkey
In the 04-chaos-monkey
directory install the dependencies:
npm install
and then zip the folder so that it can be uploaded.
zip -r chaos-monkey.zip .
Create a Lambda function
1. Create a empty Node.js v10.x lambda function
2. Upload
chaos-monkey.zip
Get some running EC2 instances
Following the post: Host a Static Webpage, running two EC2 instance with public HTTP access.
Create a CloudWatch Event
So every 1 min, it will trigger Lambda `chaos-monkey` function.
After 1 min, we can see that Function has been triggered but with error result:
We can fix this by add EC2's List and TerminateInstance policy to the Role.
Fix IAM policy
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "logs:CreateLogGroup", "Resource": "arn:aws:logs:us-east-1:645307551852:*" }, { "Effect": "Allow", "Action": [ "ec2:TerminateInstances", "ec2:DescribeInstances" ], "Resource": "*" } ] }
After that, it should work as expected. Every 1 min, cloudwatch will trigger a lambda function to turn off EC2 instances that are running. You can configure EC2 that it will automatcilly bring up again.
相关文章
- Python 恶意软件 AndroxGh0st 开始窃取 AWS 密钥
- AWS简单搭建使用EKS一
- AWS WAF bypass
- 实战教程:在AWS上构建一个情感分析「机器人」
- MySQL Error number: MY-011432; Symbol: ER_KEYRING_AWS_INCORRECT_FILE; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: MY-013493; Symbol: ER_WARN_UNKNOWN_KEYRING_AWS_REGION; SQLSTATE: HY000 报错 故障修复 远程处理
- AWS IAM 基本概念介绍
- AWS 采用自制的 KVM 作为新的管理程序
- 硬核观察 #357 ElasticSearch 继续对抗亚马逊 AWS 的开源分叉
- AWS Linux 登录指南:简单易懂的操作步骤(awslinux登录)
- 云端无限存储AWS大规模MySQL数据库管理(aws海量数据mysql)
- 云服务器上MySQL的迁移AWS解决之道(aws mysql 迁移)
- 使用AWS管理MySQL,了解相关费用支出(aws mysql 费用)
- 在AWS上搭建MySQL数据库系统的中文化指南(aws mysql 中文)
- AWS大举收购Oracle,重塑云端格局(AWS收购oracle)
- 云上极致AWS支持Oracle创造无限可能(aws支持oracle)
- 探索Oracle云和AWS的全新世界(oracle云和aws)