AWS SAM lambda授权人互联网访问



只是添加到aws-sam-cli-hello-world示例并尝试添加lambda authorizer:

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

我的lambda需要从我的租户那里获取公钥,所以我需要一个外部get调用来获取它:

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'])
... 

每次我点击lambda时,它都会超时:

Function 'MyAuthFunction' timed out after 3 seconds

我是不是遗漏了什么?我觉得我的lambda无法访问互联网

您应该将Timeout从默认的3秒增加到功能成功运行所需的时间(最多15分钟(。

例如:

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

最新更新