Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Boto3 get region during startup_fn() #297

Open
jicowan opened this issue Jan 17, 2020 · 3 comments
Open

Boto3 get region during startup_fn() #297

jicowan opened this issue Jan 17, 2020 · 3 comments
Labels
question Further information is requested

Comments

@jicowan
Copy link

jicowan commented Jan 17, 2020

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

@jicowan jicowan added the question Further information is requested label Jan 17, 2020
@jicowan
Copy link
Author

jicowan commented Jan 17, 2020

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.

@nolar
Copy link
Contributor

nolar commented Jan 20, 2020

Can you please show the error and its stack trace?

@jicowan
Copy link
Author

jicowan commented Jan 20, 2020

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants