← Cloud Practitioner study path

Practice in your account · 15 min

AWS Budgets alert on the first charge and MFA on your account

In this lab you will create an AWS Budgets alert that emails you on the first charge and you will add a second authentication factor (MFA) to the identity that owns your account.

This lab protects your account before you launch any resource, and it has two parts. In the first one you will create an AWS Budgets budget, which is an amount of money you set and that AWS watches for you: when your spending reaches it, AWS sends you an email. In the second one you will add a second authentication factor (MFA) to the identity that owns your account, so that a stolen password isn't enough to get in. Neither part charges you, because budgets and their alerts are free.

Flow of an AWS Budgets alert

A budget alert only warns you: when the email arrives, your resources keep running until you stop them. Also, Budgets updates its data up to three times a day, so the email may arrive hours after the charge. For example, if in the morning you leave the EC2 lab's server on and you have no credit left, the email may reach you in the afternoon, and the server keeps charging until you go in and turn it off.

Before you start

For this lab you will need two things:

  • Your email address, where you will receive and confirm the alert.
  • An authenticator app on your phone, such as Google Authenticator, Microsoft Authenticator, Authy, 1Password or Duo Mobile, or a security key, which you will register as a second factor. An authenticator app shows a six-digit code that changes every few seconds, and a security key is a small device that plugs into your computer or phone.

In the full account, sign in with the only for the MFA part. Any user with billing permissions, that is, with permission to see what the account spends, can create the budget. For example, if you created a user in your account for everyday work and gave it those permissions, you can do the first part with it.

Alert on the first charge

The quickest way to get this alert is the zero spend budget, an AWS Budgets template that notifies you when your spending goes over the Free Tier limits. A template is a ready-made budget, with its values already set, to which you only add your email address. For example, if a resource from a lab goes beyond what the Free Tier covers and generates a charge, this budget sends you the email. To create it, follow these steps in the :

  1. Open the Billing and Cost Management console (https://console.aws.amazon.com/cost-management/).
  2. In the navigation pane, choose Budgets.
  3. At the top, choose Create budget.
  4. In Budget setup, choose Use a template (simplified).
  5. In Templates, choose Zero spend budget.
  6. In the alert recipients, enter your email address.
  7. Choose Create budget.

The course uses a budget with a different name and different values: cloudpath-lab02-primer-centavo, for 1 USD, with an alert at 1%. 1% of 1 USD is one cent, so the alert fires with the first cent you spend. If you want yours to be the same, you can create a monthly cost budget with those values or use the CloudFormation template [lab02-presupuesto.yaml](/roadmaps/plantillas/lab02-presupuesto.yaml).

In a new experience account

In a new experience account, Budgets is in the same Billing and Cost Management console, and project members can also create budgets. However, the Budgets documentation for the new experience doesn't mention templates. If you don't see "Use a template", create a monthly cost budget of 1 USD with an alert on actual spending at 1%, which is the same one the course uses.

That same account also has the spend limit, which works differently from a budget. This limit is created in AWS Settings, only exists on the paid plan and pauses the project when spending reaches the cap. For example, if you leave the EC2 server on, a budget sends you an email and the server keeps running, while a spend limit stops the project when spending reaches the amount you set.

CloudFormation option

CloudFormation is the AWS service that creates resources from a text file called a template, and the group of resources it creates is called a stack. The lab02-presupuesto.yaml template creates the budget cloudpath-lab02-primer-centavo, which is 1 USD per month and sends an email alert when actual spending goes over 1% (one cent). The budget carries the cloudpath:lab = lab02. To create it with the template, follow these steps:

  1. In the CloudFormation console, choose Create stack and With new resources (standard).
  2. Choose Upload a template file, upload lab02-presupuesto.yaml and choose Next.
  3. Stack name: cloudpath-lab02-presupuesto. In Correo, enter your email address. Leave ContarConsumoDeCredito set to true if you want to be notified when you start spending credit.
  4. Choose Next twice and then Submit.

Create the stack in us-east-2 or in the you use. According to the data in cfn-lint, the CloudFormation template checker, this resource type doesn't exist in Mexico (mx-central-1), so if you work in that Region create the budget from the console.

How the budget counts credits

By default, a budget counts spending after subtracting credits. On the free plan, that means the alert doesn't fire while the credit covers your charges. For example, if a test costs a few cents and your credit pays for them, for the budget your spending is still zero and you don't get any email.

To find out as soon as you start spending credit, use the template with ContarConsumoDeCredito set to true. That sets IncludeCredit to false, so the budget counts the cost before subtracting the credit. With that, the same cents from the test do count as spending and you get the email.

True or false?

0 of 4
  1. When the budget alert arrives, AWS stops your resources.

  2. The alert email may arrive hours after the charge.

  3. On the free plan and with the default budget, the alert fires as soon as you start spending credit.

  4. The AWS Settings spend limit pauses the project when it reaches the cap.

MFA on your account

MFA, multi-factor authentication, adds a second factor to your password, which is the code from the authenticator app or the security key. That way, getting into your account takes two things: something you know, the password, and something you have, the phone or the key. For example, if someone gets your password but doesn't have your phone, they can't get in, because they are missing the six-digit code for that moment.

Where you register MFA depends on the account type: in the full account it goes on the root user, and in the new experience it goes on your AWS Builder ID, which is your personal AWS profile.

MFA on the root user of a full account

AWS requires MFA for the root user and accepts up to eight devices, but you have to register each one yourself. When you register it, the console shows you a QR code, a square of dots that the phone's camera reads, and with it the app saves the key to generate your codes. Follow these steps:

  1. Sign in to the console with the root user.
  2. At the top right, choose your account name and then Security credentials.
  3. In Multi-factor authentication (MFA), choose Assign MFA device.
  4. Enter a name for the device, choose Authenticator app and then Next.
  5. Choose Show QR code and scan it with the app. If your app can't read QR codes, choose Show secret key and type it into the app.
  6. Enter the code the app shows in MFA code 1. Wait for the app to show a new one (up to 30 seconds) and enter it in MFA code 2.
  7. Choose Add MFA.

AWS asks you for two codes in a row to check that the app was set up correctly and that it generates the same codes AWS expects.

cloud path tip: register a second device, in another app or on a key, so you don't get locked out of your account if you lose your phone.

MFA on your AWS Builder ID in the new experience

In the new experience there is no root user, because the owner of your projects is your Builder ID, so MFA is registered there. The AWS Settings documentation is only in English, and in it the buttons have these names:

  1. Open AWS Settings at https://settings.aws.com.
  2. In the menu, choose "Manage security and sign-in". It takes you to your AWS Builder ID profile.
  3. On the "Security" page, choose "Register device".
  4. Choose "Authenticator app" (or a security key or passkey).
  5. Choose "Show QR code" and scan it with the app, or choose "Show secret key" to type the key by hand.
  6. Enter the code from the app in "Authenticator code" and choose "Assign MFA".

AWS recommends registering more than one device, because if you lose all of them you can't recover the account. Also, if you sign in with Google, GitHub, Apple or Amazon, turn on two-step verification for that account too. For example, if you sign in to AWS with your Google account and someone steals your Google password, that person can get into your AWS, unless Google also asks them for a second factor.

Where do you add MFA?

Your account is a new experience account and you sign in with your Google account. What do you do so that a stolen password isn't enough to get in?

How to know you are done

Your budget has to appear in the Budgets console, with an alert and your email address. You can also check it from CloudShell, a window inside the console where you type commands, which are text instructions that AWS runs. For example, with this command you ask AWS for the list of your budgets with their name, amount and currency:

aws budgets describe-budgets \
  --account-id "$(aws sts get-caller-identity --query Account --output text)" \
  --region us-east-1 \
  --query "Budgets[].[BudgetName,BudgetLimit.Amount,BudgetLimit.Unit]" \
  --output table

The command uses us-east-1 because the Budgets is called in that Region, even if your account works in another one. In the new experience it works because its service control policy (SCP), which is the list of what AWS lets those accounts do, allows Budgets in that Region.

In the full account, also check the root user's MFA:

aws iam get-account-summary --query "SummaryMap.AccountMFAEnabled"

That command has to return 1, which means the root user already has MFA; a 0 means it doesn't have it yet. In the new experience there is no command for this, so check that the device appears on the "Security" page of your Builder ID.

Delete what you created

In this lab nothing is deleted, because the budget and MFA stay to protect you in the next labs. For example, if you forget to terminate the instance in the EC2 lab, this budget is what warns you. If you used the template and someday want to remove the budget, delete the stack cloudpath-lab02-presupuesto.

Next

  • Creating a budget: https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-create.html
  • cloud path practice exams: /examenes?lang=en