Activate AWS Tags in Cost Explorer
aws ce update-cost-allocation-tags-status —cost-allocation-tags-status=" TagKey='parallelcluster:cluster-name',Status='activate'"
aws ce list-cost-allocation-tags --tag-keys=' parallelcluster:cluster-name'
{
" CostAllocationTags" : [
{
" TagKey" : " parallelcluster:cluster-name" ,
" Type" : " UserDefined" ,
" Status" : " Active"
}
]
}
#!/usr/bin/python3
import boto3
PCLUSTER_COST_TAGS = ['parallelcluster:attributes' ,
'parallelcluster:cluster-name' , 'parallelcluster:compute-resource-name' , 'parallelcluster:filesystem' ,
'parallelcluster:networking' , 'parallelcluster:node-type' , 'parallelcluster:queue-name' ,
'parallelcluster:resource' , 'parallelcluster:version' ]
def check_tags ():
cost_explorer = boto3 .client ('ce' )
inactive_tags = cost_explorer .list_cost_allocation_tags (Status = 'Inactive' ,TagKeys = PCLUSTER_COST_TAGS )
try :
return {'TagStatus' : not (len (inactive_tags ['CostAllocationTags' ]) > 0 )}
except Exception as e :
return {"message" : str (e )}, 500
def activate_tags ():
try :
cost_explorer = boto3 .client ('ce' )
newlist = [{'TagKey' : tag , 'Status' : 'Active' } for tag in PCLUSTER_COST_TAGS ]
cost_explorer .update_cost_allocation_tags_status (CostAllocationTagsStatus = newlist )
return {"message" : "Activated Tags" }
except Exception as e :
return {"message" : str (e )}, 500