Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#如何在AWS Lambda调用中识别accountId和Region?_C#_Amazon Web Services_.net Core_Aws Lambda_Amazon Sns - Fatal编程技术网

c#如何在AWS Lambda调用中识别accountId和Region?

c#如何在AWS Lambda调用中识别accountId和Region?,c#,amazon-web-services,.net-core,aws-lambda,amazon-sns,C#,Amazon Web Services,.net Core,Aws Lambda,Amazon Sns,我需要识别accountId和触发AWS Lambda函数的AWS帐户的区域。我没有在ILambdaContext中找到这些信息。 我怎样才能访问这些信息? 这是由SNS引发的 我使用的是.Net Core 2.1,您可以将AccountNumber添加到环境变量中,并读取: var accountNumber = System.Environment.GetEnvironmentVariable("AccountNumber") 您可以将AccountNumber添加到环境变量并读取: va

我需要识别accountId和触发AWS Lambda函数的AWS帐户的区域。我没有在ILambdaContext中找到这些信息。 我怎样才能访问这些信息? 这是由SNS引发的
我使用的是.Net Core 2.1,您可以将AccountNumber添加到环境变量中,并读取:

var accountNumber = System.Environment.GetEnvironmentVariable("AccountNumber")

您可以将AccountNumber添加到环境变量并读取:

var accountNumber = System.Environment.GetEnvironmentVariable("AccountNumber")

如果您有权访问Lambda执行上下文,则可以从上下文对象内的InvokedLambdaFunctionArn中提取AWS区域和AWS帐户ID。
调用Lambda函数时,根据集成类型,处理程序接受一个事件对象或两个参数—请求对象和执行上下文。

如果您有权访问Lambda执行上下文,然后,您可以从上下文对象中的InvokedLambdaFunctionArn提取AWS区域和AWS帐户ID。
调用Lambda函数时,根据集成类型,处理程序接受一个事件对象或两个参数—请求对象和执行上下文。

识别帐户id的正确方法是使用安全令牌服务(STS)。使用以下方法

IAmazonSecurityTokenService.GetCallerIdentity

添加Nuget包AWSSDK.SecurityToken,然后创建sts客户端

IAmazonSecurityTokenService stsClient = new AmazonSecurityTokenServiceClient();
string accountId=stsClient.GetCallerIdentityAsync(new GetCallerIdentityRequest()).Result.Account;

识别帐户id的正确方法是使用安全令牌服务(STS)。使用以下方法

IAmazonSecurityTokenService.GetCallerIdentity

添加Nuget包AWSSDK.SecurityToken,然后创建sts客户端

IAmazonSecurityTokenService stsClient = new AmazonSecurityTokenServiceClient();
string accountId=stsClient.GetCallerIdentityAsync(new GetCallerIdentityRequest()).Result.Account;

实际上,我正在考虑不止一个帐户可以触发lambda函数,我需要触发该帐户的accountId在该帐户的SNS上发布消息。这样的话,实际上我认为不止一个帐户可以触发lambda函数,我需要触发的accountId在该帐户的SNS上发布消息。这样,它应该是友好的