Serverless Backend with AWS Lambda & API Gateway · 강의

API Gateway 권한 부여자

견고한 인증을 위해 Lambda 사용자 지정 권한 부여자와 JWT 권한 부여자를 비롯한 다양한 API Gateway 권한 부여자를 구현합니다.

레슨 2/411개 단계

API Gateway 권한 부여자은(는) CoddyKit의 무료 Serverless Backend with AWS Lambda & API Gateway 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Serverless Backend with AWS Lambda & API Gateway 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Serverless Backend with AWS Lambda & API Gateway 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

API Gateway Authorizers Intro

Welcome! In this lesson, we'll learn how to secure your serverless APIs using API Gateway Authorizers. These are crucial for controlling who can access your backend services.

Think of an authorizer as a security guard at the entrance of your API. Before any request reaches your Lambda function or other backend service, the authorizer checks the request's credentials.

Why Use API Gateway Authorizers?

Authorizers provide robust authentication and authorization for your APIs. Here's why they are essential:

  • Protect Backend Resources: Prevent unauthorized access to your Lambda functions and other services.
  • Decouple Auth Logic: Separate authentication logic from your main business logic, keeping your functions cleaner.
  • Fine-Grained Access: Control access to specific API methods or resources based on user identity or roles.

Types of Authorizers

API Gateway offers several types of authorizers. Today, we'll focus on the two most flexible and commonly used:

  • Lambda Custom Authorizers: A Lambda function you write to perform custom authentication.
  • JWT Authorizers: API Gateway's native support for validating JSON Web Tokens (JWTs).

There's also IAM Authorizers, which use AWS IAM roles and policies, but we'll focus on the custom and JWT types here.

Lambda Custom Authorizers Explained

A Lambda Custom Authorizer is a Lambda function that you provide. API Gateway invokes this function with the incoming request's authorization token (e.g., from the Authorization header).

Your Lambda function then processes this token, performs its custom authentication logic (e.g., checks a database, calls an identity provider), and returns an IAM policy.

The Authorization Policy

The core output of your Lambda authorizer is an IAM policy document. This policy tells API Gateway whether to Allow or Deny the request to the target API endpoint.

It includes a principalId (the authenticated user's identifier) and a policyDocument specifying the permissions. If Allow, the request proceeds; if Deny, it's rejected with a 401 Unauthorized error.

Lambda Authorizer Code Example

Here's a simple Python Lambda function acting as an authorizer. It checks for a specific token and returns an 'Allow' or 'Deny' policy based on it.

Try changing the token in the test event to see different outputs!

def lambda_handler(event, context):
    token = event.get('authorizationToken')
    method_arn = event.get('methodArn')

    if token == "my-secret-token-123":
        # Allow access
        return {
            "principalId": "user123",
            "policyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Action": "execute-api:Invoke",
                        "Effect": "Allow",
                        "Resource": method_arn
                    }
                ]
            }
        }
    else:
        # Deny access
        return {
            "principalId": "anonymous",
            "policyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Action": "execute-api:Invoke",
                        "Effect": "Deny",
                        "Resource": method_arn
                    }
                ]
            }
        }

# --- Local Test (for demonstration) ---
if __name__ == "__main__":
    print("Testing with 'my-secret-token-123':")
    event_allow = {
        "authorizationToken": "my-secret-token-123",
        "methodArn": "arn:aws:execute-api:us-east-1:123456789012:/test/GET/items"
    }
    print(lambda_handler(event_allow, None))

    print("\nTesting with 'invalid-token':")
    event_deny = {
        "authorizationToken": "invalid-token",
        "methodArn": "arn:aws:execute-api:us-east-1:123456789012:/test/GET/items"
    }
    print(lambda_handler(event_deny, None))

JWT Authorizers Explained

JWT (JSON Web Token) Authorizers allow API Gateway to natively validate JWTs. Instead of writing a Lambda function, you configure API Gateway with details about your JWT issuer.

When a request with a JWT comes in, API Gateway automatically performs validation steps like:

  • Signature verification
  • Expiration checks
  • Audience and issuer validation

Configuring a JWT Authorizer

To set up a JWT authorizer, you typically provide API Gateway with:

  • Issuer URL: The URL of the identity provider (e.g., https://cognito-idp.us-east-1.amazonaws.com/us-east-1_XXXXXXX for Cognito).
  • Audience(s): A list of valid audiences for the token, ensuring the token is intended for your API.
  • Identity Source: The header where the JWT is expected (e.g., $request.header.Authorization).

API Gateway then uses these details to fetch public keys and validate incoming JWTs.

When to Use Which Authorizer?

Choosing between Lambda and JWT authorizers depends on your needs:

  • Lambda Authorizer: Use for highly custom authentication logic, integration with legacy systems, or identity providers not supporting standard OIDC/OAuth2. Offers maximum flexibility.
  • JWT Authorizer: Ideal when using standard identity providers like AWS Cognito User Pools, Auth0, Okta, etc. It's simpler to set up and has less operational overhead.

For most modern applications using standard identity providers, JWT authorizers are often the preferred choice.

Authorizer Quick Check

Time for a quick check on what you've learned about API Gateway Authorizers!

Recap: Securing with Authorizers

You've now learned about API Gateway Authorizers, a vital component for securing your serverless APIs!

  • Authorizers act as a front-door security check for your API endpoints.
  • Lambda Custom Authorizers offer maximum flexibility for custom authentication logic.
  • JWT Authorizers provide native, easy-to-configure validation for standard JSON Web Tokens.

By implementing authorizers, you ensure only legitimate requests access your backend services, enhancing the security of your applications.

무료로 시작

AI 튜터와 함께 Serverless Backend with AWS Lambda & API Gateway을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
12
레슨
48

자주 묻는 질문

“API Gateway 권한 부여자” 강의는 무료인가요?

네 — “API Gateway 권한 부여자” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Serverless Backend with AWS Lambda & API Gateway 강의 전체를 잠금 해제할 수 있습니다. Serverless Backend with AWS Lambda & API Gateway 강의에는 총 4개의 강의가 포함되어 있습니다.

“API Gateway 권한 부여자”에서 뭘 배우나요?

견고한 인증을 위해 Lambda 사용자 지정 권한 부여자와 JWT 권한 부여자를 비롯한 다양한 API Gateway 권한 부여자를 구현합니다. 브라우저에서 직접 실행하는 실습 코드로 Serverless Backend with AWS Lambda & API Gateway을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Serverless Backend with AWS Lambda & API Gateway을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Serverless Backend with AWS Lambda & API Gateway은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“API Gateway 권한 부여자” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Serverless Backend with AWS Lambda & API Gateway 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Serverless Backend with AWS Lambda & API Gateway 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. IAM 역할과 권한
  2. API Gateway 권한 부여자
  3. VPC를 활용한 Lambda 보안
  4. AWS Secrets Manager로 비밀 정보 보호
← Serverless Backend with AWS Lambda & API Gateway(으)로 돌아가기