|
1 | 1 | AWSTemplateFormatVersion: "2010-09-09" |
2 | | -Description: AWS Billing Data Export Aggregation v0.1.5 |
| 2 | +Description: AWS Billing Data Export Aggregation v0.1.6 |
3 | 3 | Metadata: |
4 | 4 |
|
5 | 5 | AWS::CloudFormation::Interface: |
@@ -806,6 +806,10 @@ Resources: |
806 | 806 | - bcm-data-exports:UpdateExport |
807 | 807 | - bcm-data-exports:DeleteExport |
808 | 808 | Resource: !Sub "arn:${AWS::Partition}:bcm-data-exports:*:${AWS::AccountId}:*" |
| 809 | + - Effect: Allow |
| 810 | + Action: |
| 811 | + - bcm-data-exports:ListExports |
| 812 | + Resource: !Sub "arn:${AWS::Partition}:bcm-data-exports:*:${AWS::AccountId}:*" |
809 | 813 | - Effect: Allow |
810 | 814 | Action: |
811 | 815 | - cur:PutReportDefinition #need this permission for bcm-data-exports to work |
@@ -847,30 +851,40 @@ Resources: |
847 | 851 |
|
848 | 852 | try: |
849 | 853 | export = event['ResourceProperties']['Export'] |
850 | | - export_name = event['ResourceProperties']['Export']['Name'] |
851 | | -
|
| 854 | + old_export = event.get('OldResourceProperties', {}).get('Export') |
852 | 855 | if event['RequestType'] == 'Create': |
853 | 856 | res = client.create_export(Export=export) |
854 | 857 | print('created:', json.dumps(res)) |
855 | 858 | elif event['RequestType'] == 'Update': |
856 | | - old_export_name = event['OldResourceProperties']['Export']['Name'] |
857 | | - if export["Name"] != old_export_name: |
| 859 | + old_export_name = old_export['Name'] |
| 860 | + old_export_arn = list(client.get_paginator('list_exports').paginate().search(f"Exports[? ExportName=='{old_export_name}']"))[0]['ExportArn'] |
| 861 | + if old_export['Name'] != old_export['Name']: |
858 | 862 | res = client.create_export(Export=export) |
859 | 863 | print('created:', json.dumps(res)) |
860 | 864 | try: |
861 | | - res = client.delete_export(Name=old_export_name) |
| 865 | + res = client.delete_export(ExportArn=old_export_arn) |
862 | 866 | print('deleted:', json.dumps(res)) |
863 | | - except: |
864 | | - pass # Do not block deletion |
| 867 | + except Exception as exc: |
| 868 | + print('Exception on deletion:', str(exc)) |
| 869 | + elif export['DataQuery'] != old_export['DataQuery']: # Data export do not support update of queries |
| 870 | + print(export['DataQuery'], '!=', old_export['DataQuery']) |
| 871 | + res = client.delete_export(ExportArn=old_export_arn) |
| 872 | + print('deleted:', json.dumps(res)) |
| 873 | + res = client.create_export(Export=export) |
| 874 | + print('created:', json.dumps(res)) |
865 | 875 | else: |
866 | | - res = client.update_export(Name=old_export_name, Export=export) |
| 876 | + res = client.update_export(ExportArn=old_export_arn, Export=export) |
867 | 877 | print('updated:', json.dumps(res)) |
868 | 878 | elif event['RequestType'] == 'Delete': |
| 879 | + export_name = export['Name'] |
869 | 880 | try: |
870 | | - res = client.delete_export(Name=old_export_name) |
| 881 | + export_arn = list(client.get_paginator('list_exports').paginate().search(f"Exports[? ExportName=='{export_name}']"))[0]['ExportArn'] |
| 882 | + res = client.delete_export(ExportArn=export_arn) |
871 | 883 | print('deleted:', json.dumps(res)) |
| 884 | + except client.exceptions.ResourceNotFoundException: |
| 885 | + print('Not Found. Nothing to delete') |
872 | 886 | except: |
873 | | - pass # Do not block deletion |
| 887 | + print('Exception on deletion:', str(exc)) |
874 | 888 | else: |
875 | 889 | raise Exception("Unknown operation: " + event['RequestType']) |
876 | 890 |
|
|
0 commit comments