import%20marimo%0A%0A__generated_with%20%3D%20%220.18.1%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20auto_download%3D%5B%22html%22%5D)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Lambda%20Who%20What%20Where%0A%0A%20%20%20%20What%20are%20things%20like%20for%20your%20lambda%20function%3F%0A%0A%20%20%20%20For%20example%3A%0A%20%20%20%20-%20which%20user%20is%20it%3F%0A%20%20%20%20-%20what's%20its%20working%20directory%3F%0A%20%20%20%20-%20what's%20on%20the%20filesystem%3F%0A%20%20%20%20-%20what's%20its%20local%20time%20zone%3F%0A%20%20%20%20-%20which%20shell%20does%20it%20have%20access%20to%2C%20if%20any%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Stack%0A%0A%20%20%20%20Just%20a%20lambda%2C%20investigating%20its%20world.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Results%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20datetime%0A%20%20%20%20import%20time%0A%0A%20%20%20%20import%20boto3%0A%20%20%20%20return%20boto3%2C%20datetime%2C%20time%0A%0A%0A%40app.cell%0Adef%20_(boto3)%3A%0A%20%20%20%20lambda_%20%3D%20boto3.client(%22lambda%22)%0A%20%20%20%20logs%20%3D%20boto3.client(%22logs%22)%0A%20%20%20%20return%20lambda_%2C%20logs%0A%0A%0A%40app.cell%0Adef%20_(datetime%2C%20logs)%3A%0A%20%20%20%20def%20print_logs(function_name%2C%20start_time)%3A%0A%20%20%20%20%20%20%20%20start_time_in_ms%20%3D%20int(start_time.timestamp())%20*%201000%0A%20%20%20%20%20%20%20%20response%20%3D%20logs.filter_log_events(%0A%20%20%20%20%20%20%20%20%20%20%20%20logGroupName%3Df%22%2Faws%2Flambda%2F%7Bfunction_name%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20startTime%3Dstart_time_in_ms%2C%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20nice_logs%20%3D%20%22%22%0A%20%20%20%20%20%20%20%20for%20event%20in%20response%5B%22events%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20t%20%3D%20datetime.datetime.fromtimestamp(event%5B%22timestamp%22%5D%20%2F%201000%2C%20datetime.UTC)%0A%20%20%20%20%20%20%20%20%20%20%20%20message%20%3D%20event%5B%22message%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20nice_logs%20%2B%3D%20f%22%7Bt%7D%3A%20%7Bmessage%7D%22%0A%0A%20%20%20%20%20%20%20%20print(nice_logs)%0A%20%20%20%20return%20(print_logs%2C)%0A%0A%0A%40app.cell%0Adef%20_(datetime%2C%20lambda_%2C%20print_logs%2C%20time)%3A%0A%20%20%20%20call_time%20%3D%20datetime.datetime.now(datetime.UTC)%0A%20%20%20%20lambda_.invoke(FunctionName%3D%22who_what_where%22)%0A%20%20%20%20time.sleep(60)%20%20%23%20give%20logs%20time%20to%20appear%0A%20%20%20%20print_logs(%22who_what_where%22%2C%20call_time)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20user%20is%20%60sbx_user1051%60%2C%20not%20%60root%60.%0A%20%20%20%20The%20%601051%60%20looks%20random%20to%20me%2C%0A%20%20%20%20but%20it%20does%20persist%20across%20invocations%2C%20cold%20and%20warm%2C%20and%20cdk%20updates.%0A%20%20%20%20I%20wonder%20if%20it's%20the%20same%20across%20runtimes.%0A%0A%20%20%20%20The%20working%20directory%20is%20%60%2Fvar%2Ftask%60%2C%0A%20%20%20%20containing%20just%20the%20lambda%20code%2C%0A%20%20%20%20which%20makes%20sense.%0A%0A%20%20%20%20%60%2F%60%20contains%20some%20things%20of%20interest%2C%0A%20%20%20%20e.g.%20%60lambda-entrypoint.sh%60%2C%0A%20%20%20%20which%20I'll%20look%20at%20another%20time.%0A%0A%20%20%20%20The%20function%20can't%20write%20to%20its%20working%20directory%2C%0A%20%20%20%20nor%20presumably%20anywhere%2C%0A%20%20%20%20(except%20for%20%60%2Ftmp%60%2C%20which%20is%20provided%20explicitly%20for%20ephemeral%20storage).%0A%0A%20%20%20%20The%20shell%20is%20GNU%20bash.%0A%20%20%20%20And%20the%20stdout%20of%20the%20subprocess%20running%20via%20the%20shell%20shows%20up%20in%20the%20logs.%0A%20%20%20%20That%20also%20makes%20sense%3A%20stdout%20is%20logged%2C%20no%20matter%20its%20source.%0A%20%20%20%20There's%20no%20%60SHELL%60%20environment%20variable.%0A%0A%20%20%20%20%60time.tzname%60%20is%0A%0A%20%20%20%20%3E%20A%20tuple%20of%20two%20strings%3A%20the%20first%20is%20the%20name%20of%20the%20local%20non-DST%20timezone%2C%20the%20second%20is%20the%20name%20of%20the%20local%20DST%20timezone.%0A%0A%20%20%20%20Its%20value%20for%20me%20locally%20(in%20the%20UK)%20is%20%60('GMT'%2C%20'BST')%60.%0A%20%20%20%20But%20in%20the%20lambda%20it's%20%60('UTC'%2C%20'UTC')%60.%0A%20%20%20%20I%20presume%20that's%20the%20case%20no%20matter%20the%20region.%0A%20%20%20%20Which%20is%20nice%3A%20one%20less%20thing%20to%20worry%20about.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
ae88bc3dfb61ce01f8b3359a31884fb5