Deploying a CloudFormation stack in an AWS account and set up, everything needed for budget notifications, follow these steps:

Victor Okonkwo - Aug 22 - - Dev Community

1. Prepare Your CloudFormation Template

Ensure your CloudFormation template file (e.g., budget-notification.yaml) includes the IAM Role, Lambda Function, SNS Topic, Event Rule, and permissions.

2. Install and Configure AWS CLI

Ensure the AWS CLI is installed and configured with credentials for the new AWS account. Use the following commands to configure it:

aws configure
Enter fullscreen mode Exit fullscreen mode

Enter your new AWS account credentials and default region when prompted.

3. Create the CloudFormation Stack

Deploy the CloudFormation stack using the AWS CLI with the following command:

aws cloudformation create-stack --stack-name BudgetNotificationStack --template-body file://budget-notification.yaml --capabilities CAPABILITY_NAMED_IAM
Enter fullscreen mode Exit fullscreen mode

4. Verify the Stack Creation

Check the status of the stack to ensure it's created successfully:

aws cloudformation describe-stacks --stack-name BudgetNotificationStack
Enter fullscreen mode Exit fullscreen mode

5. Create a Budget in AWS Budgets

You’ll need to create a budget that matches the name used in the Lambda function (MyDailyBudget9). Here’s a sample command to create a budget using the AWS CLI:

aws budgets create-budget --account-id <your-account-id> --budget "{\"BudgetName\":\"MyDailyBudget9\",\"BudgetLimit\":{\"Amount\":\"300.0\",\"Unit\":\"USD\"},\"CostFilters\":{},\"CostTypes\":{\"IncludeTax\":true,\"IncludeSubscription\":true,\"UseBlended\":false,\"IncludeRefund\":true,\"IncludeCredit\":true,\"IncludeUpfront\":true,\"IncludeRecurring\":true,\"IncludeOtherSubscription\":true,\"IncludeSupport\":true,\"IncludeDiscount\":true,\"UseAmortized\":false},\"TimeUnit\":\"DAILY\",\"BudgetType\":\"COST\"}"
Enter fullscreen mode Exit fullscreen mode

Replace <your-account-id> with your new AWS account ID.

6. Verify Budget Creation

Ensure the budget is created by listing budgets:

aws budgets describe-budgets --account-id <your-account-id>
Enter fullscreen mode Exit fullscreen mode

7. Confirm SNS Email Subscriptions

After creating the stack, check the SNS Topic subscriptions to confirm that the email addresses have been added. You should receive an email asking you to confirm the subscription. Follow the link in the email to confirm.

List SNS topics to find the topic ARN:

aws sns list-topics
Enter fullscreen mode Exit fullscreen mode

List subscriptions to verify:

aws sns list-subscriptions
Enter fullscreen mode Exit fullscreen mode

8. Verify Lambda Function Execution

Test the Lambda function to ensure it’s triggered correctly. You can manually invoke the Lambda function to verify it works:

aws lambda invoke --function-name DailyBudgetReportFunction output.txt
Enter fullscreen mode Exit fullscreen mode

Check the output in output.txt and the CloudWatch Logs for any errors.

Summary of Commands

  1. Deploy Stack:
   aws cloudformation create-stack --stack-name BudgetNotificationStack --template-body file://budget-notification.yaml --capabilities CAPABILITY_NAMED_IAM
Enter fullscreen mode Exit fullscreen mode
  1. Check Stack Status:
   aws cloudformation describe-stacks --stack-name BudgetNotificationStack
Enter fullscreen mode Exit fullscreen mode
  1. Create Budget:
   aws budgets create-budget --account-id <your-account-id> --budget "{\"BudgetName\":\"MyDailyBudget9\",\"BudgetLimit\":{\"Amount\":\"300.0\",\"Unit\":\"USD\"},\"CostFilters\":{},\"CostTypes\":{\"IncludeTax\":true,\"IncludeSubscription\":true,\"UseBlended\":false,\"IncludeRefund\":true,\"IncludeCredit\":true,\"IncludeUpfront\":true,\"IncludeRecurring\":true,\"IncludeOtherSubscription\":true,\"IncludeSupport\":true,\"IncludeDiscount\":true,\"UseAmortized\":false},\"TimeUnit\":\"DAILY\",\"BudgetType\":\"COST\"}"
Enter fullscreen mode Exit fullscreen mode
  1. List Budgets:
   aws budgets describe-budgets --account-id <your-account-id>
Enter fullscreen mode Exit fullscreen mode
  1. List SNS Topics:
   aws sns list-topics
Enter fullscreen mode Exit fullscreen mode
  1. List SNS Subscriptions:
   aws sns list-subscriptions
Enter fullscreen mode Exit fullscreen mode
  1. Invoke Lambda Function:
   aws lambda invoke --function-name DailyBudgetReportFunction output.txt
Enter fullscreen mode Exit fullscreen mode

Following these steps will set up the CloudFormation stack, create the required budget, and ensure that the Lambda function and SNS notifications are correctly configured.

. . .
Terabox Video Player