AWS lambda expected intended block error in Python

I am following the below document to connect to Cloudwatch logs to ELK. I get a “expected an indented block” syntax error in python for this line. try: logs = awslogs_handler(s, event) Can someone help me figure this out? Not sure what im missing. Thanks! Answer You need to use something like this: An indent block(contains four whitespaces) are required. You can read more here

Serving static files in elastick beanstalk

I’m deploying a python3 flask application in aws elasitc beanstalk (Amazon Linux 2 platform). The folder structure is as follows: In the template files, importing of static resources are defiled as: i.e. JS file: In the EB configurations, I’ve defined the static resources as below But the problem is, these resources are not loading and giving 404. i.e.: cannot be loaded. But if I try, it works. Have I done the configurations wrong?? Answer Based on the comments. The issue was due to overwriting /static path. In python EB environments, /static path is used by default to server

Amazon S3 boto3 how to iterate through objects in a bucket?

In a flask app, I was trying to iterate through objects in a S3 Bucket and trying to print the key/ filename but my_bucket.objects.all() returns only the first object in the bucket. It’s not returning the all the objects. The output is [001.pdf] instead of [001, 002, 003, 004, 005] Answer You are exiting the loop by returning too early.

For loop is taking only the last element in the list

I am sorry for a simple question, but tried multiple options without any solution. he Problem I have is the for loop is taking only the last value in the list(Regions). This is the list and it takes only the last value It has to take all the values in the list(Regions) and display the result. But it takes only the last value(us-east-1). Please advice what is causing the error. Answer Here: you are creating a new csv file for each region, overwriting the previous one. You want to keep this out of the loop:

How to describe snapshots by OwnerIds and Filters using boto3

How to describe snapshots owned by me and filtering by tag simultaneously? It describe snapshots owned by me with code below: But when I add “Filters”, its starts ignoring “OwnerIds” and filtering only by tag. I’m follow an official boto3 documentation: Answer I think the Filters and OwnerIds options are working separately. I expect that the OwnerIds option is an abbreviation of the Filters option for owner-id, because I also got the result that the OwnerIds option is ignored. And so, you can use the filter option such as and it will work well same as me.

Boto3: grabbing only selected objects from the S3 resource

I can grab and read all the objects in my AWS S3 bucket via and then would give me the path within the bucket. Is there a way to filter beforehand for only those files respecting a certain starting path (a directory in the bucket) so that I’d avoid looping over all the objects and filtering later? Answer Use the filter[1], [2] method of collections like bucket.