Infra类似于具有处理程序Lambda函数的API网关。我们为3个客户端创建了3个IAM用户,客户端通过提供访问权限和密钥来执行API网关。我想获取访问和密钥以标识用户。 下面的代码(在lambda中)有助于我们获取用户详细信息。
AWSCredentialsProvider credProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials("accessKey","secretKey"))
AmazonIdentityManagementClientBuilder.standard().withCredentials(credProvider).build()
如何获取访问权限和密钥?处理函数中的上下文对象仅提供认知身份对象,但是我一直期望在api调用期间使用具有访问权限和密钥的IAM身份对象。
答案 0 :(得分:0)
实施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中获得用户ID和accessKey。