1. 모든 람다의 메서드 요청 설정에 권한부여 GitmagotchiAuthorizer해주기

Untitled

2. 통합요청 → Lambda 프록시 통합 True ⭐

Untitled

3. Java에서 직접 꺼내오기

package user.handler;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import org.json.JSONObject;

public class Test0513Handler implements
    RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {

    @Override
    public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent request,
        Context context) {

        APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();

        JSONObject requestObj = new JSONObject(request);
        
        JSONObject requestContext = requestObj.getJSONObject("requestContext");
        
        JSONObject authorizer = requestContext.getJSONObject("authorizer");

        JSONObject claims = authorizer.getJSONObject("claims");

        // username: github_125880884
        String username = claims.getString("cognito:username"); 

        String userId = username.replace("github_", "");
        
        // 찐 userId !!!
        context.getLogger().log("userId: " + userId);

        return response;
    }

}

간단하게 합치면

        JSONObject requestObj = new JSONObject(request);
        
        JSONObject requestContext = requestObj.getJSONObject("requestContext")
            .getJSONObject("authorizer").getJSONObject("claims");
        String username = requestContext.getString("cognito:username");
        
        Integer userId = Integer.parseInt(username.replace("github_", ""));