LoginSignup
1
2

More than 3 years have passed since last update.

Amazon Cognitoの認証情報をAmazon API Gateway+AWS Lambdaで取得

Posted at

Goで取得してみます。

APIGatewayの統合リクエストで Lambdaプロキシ統合の使用 にチェックを入れてください。

Go側では、github.com/aws/aws-lambda-go/eventsevents.APIGatewayProxyRequest で受け取ります。
下記のように取れます。

func handler(ctx context.Context, req events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
    claims := req.RequestContext.Authorizer["claims"].(map[string]interface{})
    res := &events.APIGatewayProxyResponse{
        StatusCode: 200,
        Body:       claims["cognito:username"].(string),
    }
    return res, nil
}

func main() {
    lambda.Start(handler)
}

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2