简体   繁体   中英

AWS SAM lambda authorizer internet access

Just adding to aws sam cli hello world example and trying to add lambda authorizer:

MyAuthFunction:
  Type: AWS::Serverless::Function
  Properties:
    CodeUri: ./python
    Handler: auth/authorizer.lambda_handler
    Runtime: python3.8

My lambda needs to get a public key from my tenant so I need an external get call to get it:

def lambda_handler(event, context):
  ...
  print("getting pub key from", 'https://%s/pem' % os.environ['AUTH_DOMAIN'])
  pub_key = requests.get('https://%s/pem' % os.environ['AUTH_DOMAIN'])
  ... 

Every time I hit the lambda it gets timed out:

Function 'MyAuthFunction' timed out after 3 seconds

Am I missing something here? I feel like my lambda doesn't have access to the internet

You should increase Timeout , from default 3 seconds to whatever is required for your function to work successful (max 15 min).

For example:

MyAuthFunction:
  Type: AWS::Serverless::Function
  Properties:
    CodeUri: ./python
    Handler: auth/authorizer.lambda_handler
    Runtime: python3.8
    Timeout: 60 # one minute

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM