Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boto3 get region during startup_fn() #297

Open
kopf-archiver bot opened this issue Aug 18, 2020 · 0 comments
Open

Boto3 get region during startup_fn() #297

kopf-archiver bot opened this issue Aug 18, 2020 · 0 comments
Labels
archive question Further information is requested

Comments

@kopf-archiver
Copy link

kopf-archiver bot commented Aug 18, 2020

An issue by jicowan at 2020-01-17 17:58:23+00:00
Original URL: zalando-incubator/kopf#297
 

Question

I am calling a method in my startup_fn() that queries instance metadata to get the region. I use the region to create global environment variables for boto3 clients like ec2 and eks. When the code runs, I get an error that the region must be set. How should I handle this?

Here is the code I'm using in my startup_fn():

@kopf.on.startup()
async def startup_fn(logger, **kwarg):
    global region, eks, ec2, iam, cluster_name
    cluster_name, region = get_metadata()
    eks = client('eks', region_name=region)
    ec2 = client('ec2', region_name=region)
    iam = resource('iam')

Checklist

  • [ x] I have read the documentation and searched there for the problem
  • [ x] I have searched in the GitHub Issues for similar questions

Keywords


Commented by jicowan at 2020-01-17 19:23:32+00:00
 

When I moved the variable declarations out of the handler, it worked. I wanted to do it as part of the setup handler; I'm using the HTTP request library to call ec2 metadata: get_metadata(). I didn't want the operator to start until the region was set.


Commented by nolar at 2020-01-20 11:44:05+00:00
 

Can you please show the error and its stack trace?


Commented by jicowan at 2020-01-20 15:41:47+00:00
 

nolar I will have to move the code back to the startup handler to get the trace. It basically said that the region was not set when it when I referenced the variables in the create handler.

@kopf-archiver kopf-archiver bot closed this as completed Aug 18, 2020
@kopf-archiver kopf-archiver bot changed the title [archival placeholder] Boto3 get region during startup_fn() Aug 19, 2020
@kopf-archiver kopf-archiver bot added the question Further information is requested label Aug 19, 2020
@kopf-archiver kopf-archiver bot reopened this Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archive question Further information is requested
Projects
None yet
Development

No branches or pull requests

0 participants