amazon-web-services - 使用 AWS 控制台自动激活接收账单提醒选项

标签 amazon-web-services aws-cloudformation aws-cdk

我正在寻找一种自动方式来激活 AWS 账单首选项以接收账单警报的选项。据了解,这是从 Cloudwatch 接收账单提醒的要求。

我搜索了 boto3 引用文档,但没有成功。我不想使用像提及here这样的静态检查.

对我来说,在一定的时间和阈值上进行一些扫描似乎是理想的解决方案。

我正在考虑 CustomResource在帐户设置堆栈中激活此选项。

提前致谢!

最佳答案

感谢@Dvir669。我发现,AWS Budgets根据区域(全局服务,具有区域端点)不受限制地解决我的问题,并且无需更改计费首选项。但AWS Budgets配备了复杂的计费仪表板。最后,警报通知格式良好,默认情况下不需要 SNS 主题。我附上一张照片。

enter image description here

在 CDK 中,配置 AWS 预算非常简单:

# CDK Libs
from aws_cdk import core
from aws_cdk import aws_budgets as _budgets

class BillingAlertStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # The code that defines your stack goes here

        #####################
        # Emails for Alerts
        #####################

        emails_list = [
            "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9a0b6acabbcb4b8b0b5e899bca1b8b4a9b5bcf7bab6b4" rel="noreferrer noopener nofollow">[email protected]</a>",
            ...
        ]

        #####################
        # Thresholds for Alerts
        #####################

        thresholds_list = [
            15,
            ...
        ]

        #####################
        # Budget Alert
        #####################

        subscribers_list=[]

        for emails in emails_list:
            subscribers_list.append(
                _budgets.CfnBudget.SubscriberProperty(
                    address=emails,
                    subscription_type="EMAIL"
                )
            )

        for thresholds in thresholds_list:
            property= _budgets.CfnBudget.BudgetDataProperty(
                budget_type="COST",
                budget_limit=_budgets.CfnBudget.SpendProperty(
                    amount=thresholds,
                    unit="USD"
                ),
                time_unit="MONTHLY",
            )
            budgets = _budgets.CfnBudget(
                self,
                id="Budget-{}".format(thresholds),
                budget=property,
                notifications_with_subscribers=[
                    _budgets.CfnBudget.NotificationWithSubscribersProperty(
                        notification=_budgets.CfnBudget.NotificationProperty(
                            comparison_operator="GREATER_THAN",
                            notification_type="ACTUAL",
                            threshold=80,
                            threshold_type="PERCENTAGE"
                        ),
                        subscribers=subscribers_list
                    )
                ]
            )

如您所见,到目前为止,还没有详细的构造可用,但 Python 本身比普通的 CloudFormation 具有优势。在 app.py 中,您可以一次指定多个帐户。在 AWS Organizations 内的 OU 上应用 AWS 预算是非常有意义的。

关于amazon-web-services - 使用 AWS 控制台自动激活接收账单提醒选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60751764/

相关文章:

ssh - 使用SSH连接到Amazon EC2实例时禁用未确认的主机确认

amazon-web-services - CloudFormation API 网关 CORS 问题对 XMLHttpRequest 的访问被阻止

amazon-web-services - Cloudformation 自定义资源

amazon-web-services - AWS CloudFormation - 加载 JSON 映射作为模板参数

aws-cdk - 如何在不部署的情况下获取 CfnOutput

python - 使用初始数据填充 Amazon DynamoDB 表 python CDK

amazon-web-services - 如何从AWS Lambda函数获取返回响应

ios - iOS Amazon Cognito登录错误InvalidParameterException

amazon-web-services - 将partitionKey添加到Timestream表(或者创建不存在的资源)

amazon-web-services - aws 安全组的 Terraform 中的变量值