AWS账单预算在警告违规行为后怎么处理?
创始人
2024-09-28 01:30:55
0

可以使用AWS Budgets的Webhooks功能,在警告阈值被触发时向SNS主题发送一个JSON消息。SNS主题可以通过AWS Lambda函数将消息传递给必要的服务或应用程序,并触发必要的操作,比如停止EC2实例或终止ECS任务。

示例代码:

  1. 创建SNS Topic
import boto3

# set up AWS credentials and create SNS client
session = boto3.Session(profile_name='my_profile')
sns = session.client('sns', region_name='us-east-1')

# create SNS Topic
sns_topic_arn = sns.create_topic(Name='billing_alert_topic')['TopicArn']
  1. 创建Lambda函数
import json
import boto3

def lambda_handler(event, context):

    # extract budget details and alert threshold from JSON message
    budget_details = event['budget']
    alert_threshold = event['alertThreshold']
    
    # check if costs exceeded the alert threshold
    cost_exceeds_threshold = float(budget_details['budgetedAndActualAmounts']['actualAmount']) >= float(alert_threshold)
    
    # if costs exceed threshold, terminate EC2 instance with specified instance id
    if cost_exceeds_threshold:
        instance_id = 'i-12345'
        
        ec2 = boto3.resource('ec2', region_name='us-east-1')
        ec2.Instance(instance_id).terminate()
  1. 创建Webhook

将SNS主题绑定到Budgets预算提醒操作的Webhook中,并指定Lambda函数作为处理程序。

  1. 测试

手动修改预算并使其超过警告阈值,触发Lambda函数并自动在AWS中终止EC2实例。

相关内容

热门资讯

外挂演示!约局吧辅助器,agp... 外挂演示!约局吧辅助器,agpoker辅助-一直一直都是有辅助教程(哔哩哔哩)1、约局吧辅助器免费脚...
外挂课程!拱趴大菠萝开挂方法,... 外挂课程!拱趴大菠萝开挂方法,pokerrrr2辅助-确实存在有辅助工具(哔哩哔哩)暗藏猫腻,小编详...
外挂模板!uupoker有透视... 外挂模板!uupoker有透视吗,约局吧开挂神器是真的吗-一直真的是有辅助方法(哔哩哔哩)1、约局吧...
外挂教材!佛手在线大菠萝辅助,... 外挂教材!佛手在线大菠萝辅助,拱趴大菠萝万能辅助器-都是是真的有辅助攻略(哔哩哔哩)外挂教材!佛手在...
外挂演示!德州私人局脚本,po... 外挂演示!德州私人局脚本,pokermaster修改器-竟然存在有辅助攻略(哔哩哔哩)德州私人局脚本...
外挂项目!xpoker辅助控制... 外挂项目!xpoker辅助控制,pokernow辅助控制-本来真的是有辅助方法(哔哩哔哩)所有人都在...
外挂办法!哈糖大菠萝开挂,德普... 外挂办法!哈糖大菠萝开挂,德普之星私人局辅助免费-原来一直总是有辅助教程(哔哩哔哩)哈糖大菠萝开挂是...
外挂窍门!拱趴大菠萝怎么开挂,... 外挂窍门!拱趴大菠萝怎么开挂,智星菠萝透视-确实有辅助技巧(哔哩哔哩)1、拱趴大菠萝怎么开挂脚本辅助...
外挂课程!菠萝辅助器免费版的功... 外挂课程!菠萝辅助器免费版的功能介绍,来玩app破解-总是真的有辅助神器(哔哩哔哩);进入游戏-大厅...
外挂大纲!约局吧游戏挂,soh... 外挂大纲!约局吧游戏挂,sohoo竞技联盟辅助器-一直真的有辅助app(哔哩哔哩)1)sohoo竞技...