-2

I have a list containing date values in this format (datetime.datetime(2021, 9, 1, 8, 30, 25, 430000, tzinfo=tzlocal())). I would like to convert this date values into ISO Format. Purpose being CloudWatch Log Insight could not read this date format.

Output:

[{'timestamp': datetime.datetime(2021, 9, 1, 8, 30, 25, 430000, tzinfo=tzlocal()), 'type': 'ExecutionFailed', 'id': 22, 'previousEventId': 21, 'executionFailedEventDetails': {'error': 'States.TaskFailed', 'cause': '{"AllocatedCapacity":2,"Attempt":0,"CompletedOn":1630485024021,"ErrorMessage":"An error occurred while calling o80.getDynamicFrame. The TCP/IP connection to the host 172.31.17.102, port 1433 has failed. Error: \\"Connection timed out: no further information. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.\\".","ExecutionTime":100,"GlueVersion":"2.0","Id":"jr_504a3acc2cdb7e3e18d2d22d8df69747744030e24afbcbee7f02de1ece6599c3","JobName":"sqlserver-ingest","JobRunState":"FAILED","LastModifiedOn":1630485024021,"LogGroupName":"/aws-glue/jobs","MaxCapacity":2.0,"NumberOfWorkers":2,"PredecessorRuns":[],"StartedOn":1630484906355,"Timeout":2880,"WorkerType":"G.1X"}'}}]
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
Michelle Santos
  • 257
  • 4
  • 20

1 Answers1

1

Use datetime.isoformat()

import datetime
from dateutil.tz import tzlocal

dt = datetime.datetime(2021, 9, 1, 8, 30, 25, 430000, tzinfo=tzlocal())
dt_iso = dt.isoformat()
print(type(dt_iso), dt_iso)
<class 'str'> 2021-09-01T08:30:25.430000+00:00