如何确定AWS Lambda函数中的当前区域? [英] How can one determine the current region within an AWS Lambda function?

查看:591
本文介绍了如何确定AWS Lambda函数中的当前区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Regions.getCurrentRegion()从AWS Lambda函数中返回null。 AWS Lambda函数似乎不支持 Regions.getCurrentRegion()。是否有另一种方法可以确定lambda函数在哪个区域运行?

Regions.getCurrentRegion() returns null from within an AWS Lambda function. It seems that Regions.getCurrentRegion() is not supported from within an AWS Lambda function. Is there an alternative way to determine which region the lambda function is running in?

注意:AWS Lambda函数是用Java编写的。

NOTE: AWS Lambda function is written in Java.

推荐答案

您可以阅读 AWS_DEFAULT_REGION 环境变量并使用 Regions.fromName 将其解析为可用区域的函数。

You can read the AWS_DEFAULT_REGION environment variable and use the Regions.fromName function to parse that into a useable region.

Regions.fromName(System.getenv("AWS_DEFAULT_REGION"))

这比ARN解析方法的优点是你不需要一个Context对象,这意味着你可以在你的处理函数之外使用它。

The advantage of this over the ARN parsing approach is that you do not need a Context object which means you can use it outside of your handler function.

来源: AWS的Lambda环境变量docs

这篇关于如何确定AWS Lambda函数中的当前区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆