【问题标题】:Fetch AWS Access And Secret Key获取 AWS 访问和密钥
【发布时间】:2020-12-14 08:22:43
【问题描述】:

Infra 类似于具有处理程序 Lambda 函数的 API 网关。我们为 3 个客户端创建了 3 个 IAM 用户,客户端通过提供访问权限和密钥来执行 API 网关。我想获取访问和密钥来识别用户。 下面的代码(在 lambda 中)帮助我们获取用户详细信息。

AWSCredentialsProvider credProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials("accessKey","secretKey"))
AmazonIdentityManagementClientBuilder.standard().withCredentials(credProvider).build()

如何获取访问和密钥?处理函数中的上下文对象仅提供 cognito 身份对象,但是我一直期待 IAM 身份对象具有在 api 调用期间使用的访问权限和密钥。

【问题讨论】:

    标签: java amazon-web-services aws-lambda amazon-iam


    【解决方案1】:

    实现 RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> 。 对于每个传入的请求事件,您将在 APIGatewayProxyRequestEvent

    中获得以下详细信息
    requestEvent.getRequestContext().getIdentity() 
    

    包含

        private String cognitoIdentityPoolId;
        private String accountId;
        private String cognitoIdentityId;
        private String caller;
        private String apiKey;
        private String sourceIp;
        private String cognitoAuthenticationType;
        private String cognitoAuthenticationProvider;
        private String userArn;
        private String userAgent;
        private String user;
        private String accessKey;
    

    如您所见,您将在 userARN 中获得 userID 以及 accessKey。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-02
      • 2014-09-12
      • 1970-01-01
      • 2019-10-10
      • 1970-01-01
      • 2017-03-23
      • 1970-01-01
      • 2021-12-25
      相关资源
      最近更新 更多