aws-samples / coast-grafana-cost-intelligence-dashboards

MIT No Attribution
10 stars 2 forks source link

Error deleting Grafana datasource #8

Closed pelgrim closed 5 months ago

pelgrim commented 5 months ago

When deleting the CFN stack, the Lambda that manages the datasource resource raised:

DELETE https://<url>api/datasources/1 None
Status: 200
b'
{
    "message": "Data source deleted"
}
'
Error:'id'
amazonchris commented 5 months ago

Deletion request to the Lambda Custom Resource named 'GrafanaDataSourceFunction':

[INFO] 2024-01-23T16:58:42.399Z babaa255-5dcf-4d55-a6a3-51cb4f9b2451 Failed attempting to delete datasource COAST-2023-09-19: Failed calling grafana api to retrieve datasources

amazonchris commented 5 months ago

The delete lambda identifies the datasource by name, and it pulls the ID of the datasource. However, the grafana call to the api endpoint is done by UID


          datasource_id = None
          for datasource in datasources:
              if datasource['name'] == self.datasource_name:
                  datasource_id = datasource['id']
                  break

          return self.grafana_api('DELETE',f'datasources/uid/{datasource_id}')
amazonchris commented 5 months ago

Requests was not imported into the code for this to succeed:

response = requests.get(grafana_url, headers={'Authorization': f"Bearer {key}",'Content-Type': 'application/json'})