Setup AWS Costs
env0 will assume an AWS IAM Role in your account, in order to query AWS's billing API.
Read more about cross account role delegation.
To begin, log in to your AWS Console, and select the Identity and Access Management (IAM) service.
Create an AWS IAM Policy
- Click on Policies -> Create Policy
- Select the Cost Explorer Service
- Select the
GetCostAndUsage
Action - Choose a name for your policy and save it.
Create an AWS IAM Role
- Click on Roles -> Create Role
- Under type of trusted entity select
Another AWS Account
- Under Account ID enter
913128560467
- Select
**Require external ID**
- Enter an External ID. The value Must be equal to your organization ID.
- Click Next:Permissions
- Select the policy you created in step 2.
- Click Next:Tags
- Click Next:Review
- Enter a name for the role, and click Create Role
- Click on the Role you just created - We will need the
Role ARN
in subsequent steps.
Enable User Defined Cost Allocation Tags
- Add the Tags called
env0_environment_id
andenv0_project_id
to some resource in your AWS account - Make sure that you add those tags to a resource that has some cost to it, for example an EC2 instance. - Go to the "Billing" Service (Billing & Cost Management). You'll need to log into to the parent account, if you are using sub-accounts.
- Under the left side menu, click Cost allocation tags.
- Under the User-Defined Cost Allocation Tags section, check the checkboxes for the tag-keys
env0_environment_id
andenv0_project_id
. Pay attention that those tags might be available in Cost Allocation Tags only after a few days, usually it's 24 hours but we've seen cases where it took a week for them to show up. - Click Activate
Note
After this step, it can take up to 24 hours to see actual cost values in your environments.
Enable Hourly and Resource Level Data
- Go to the "Billing" Service (Billing & Cost Management). You'll need to log into to the parent account, if you are using sub-accounts.
- Under the left side menu, click Cost Explorer.
- Click on the Launch Cost Explorer button.
- In the Cost Explorer page on the left side menu click on Preferences.
- Under the Hourly and Resource Level Data enable the Hourly and Resource Level Data checkbox and save the changes.
Add Credentials to your Organization
- Under your Organization Settings, Select the Credentials tab
- Under Cost Credentials, click Add Credential
- Select the AWS Assumed Role type, and enter the
Role ARN
from the previous step. The External ID cannot be edited. - Click Add
- Re-run the environments to apply the necessary tags.
Drift after re-running environments
Note that enabling costing introduces drift as new tags will be injected into your resources
Enable cost monitoring
- Go to the Project Settings of the desired project.
- Select the Credentials tab.
- Check the appropriate cloud provider checkbox, and select the credential you created in the steps above.
- Click Save.
Updated 5 months ago