Lambda 권한 부여자 예제 - AWS Serverless Application Model

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Lambda 권한 부여자 예제

AWS::Serverless::Api 리소스 유형은 두 가지 유형의 Lambda 권한 부여자, 즉 TOKEN 권한 부여자와 REQUEST 권한 부여자를 지원합니다. AWS::Serverless::HttpApi리소스 유형은 REQUEST 권한 부여자만 지원합니다. 다음은 각 유형의 예입니다.

Lambda TOKEN 권한 부여자 예제(AWS::Serverless::Api)

템플릿 내에 TOKEN Lambda 권한 부여자를 정의하여 API에 대한 액세스를 제어할 수 있습니다. AWS SAM 이 작업을 수행하려면 ApiAuth 데이터 유형을 사용합니다.

다음은 TOKEN Lambda 권한 부여자를 위한 예제 AWS SAM 템플릿 섹션입니다.

참고

다음 예시에서는 SAM이 암시적으로 FunctionRole 생성됩니다.

Resources: MyApi: Type: AWS::Serverless::Api Properties: StageName: Prod Auth: DefaultAuthorizer: MyLambdaTokenAuthorizer Authorizers: MyLambdaTokenAuthorizer: FunctionArn: !GetAtt MyAuthFunction.Arn MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Handler: index.handler Runtime: nodejs12.x Events: GetRoot: Type: Api Properties: RestApiId: !Ref MyApi Path: / Method: get MyAuthFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Handler: authorizer.handler Runtime: nodejs12.x

Lambda 권한 부여자에 대한 자세한 내용은 API Gateway 개발자 안내서API Gateway Lambda 권한 부여자 사용을 참조하세요.

Lambda REQUEST 권한 부여자 예제(AWS::Serverless::Api)

템플릿 내에 REQUEST Lambda 권한 부여자를 정의하여 API에 대한 액세스를 제어할 수 있습니다. AWS SAM 이 작업을 수행하려면 ApiAuth 데이터 유형을 사용합니다.

다음은 REQUEST Lambda 권한 부여자를 위한 예제 AWS SAM 템플릿 섹션입니다.

Resources: MyApi: Type: AWS::Serverless::Api Properties: StageName: Prod Auth: DefaultAuthorizer: MyLambdaRequestAuthorizer Authorizers: MyLambdaRequestAuthorizer: FunctionPayloadType: REQUEST FunctionArn: !GetAtt MyAuthFunction.Arn Identity: QueryStrings: - auth MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Handler: index.handler Runtime: nodejs12.x Events: GetRoot: Type: Api Properties: RestApiId: !Ref MyApi Path: / Method: get MyAuthFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Handler: authorizer.handler Runtime: nodejs12.x

Lambda 권한 부여자에 대한 자세한 내용은 API Gateway 개발자 안내서API Gateway Lambda 권한 부여자 사용을 참조하세요.

Lambda 권한 부여자 예제(AWS::Serverless::HttpApi)

템플릿 내에 Lambda 권한 부여자를 정의하여 HTTP API에 대한 액세스를 제어할 수 있습니다. AWS SAM 이 작업을 수행하려면 HttpApiAuth 데이터 유형을 사용합니다.

다음은 Lambda 권한 부여자를 위한 예제 AWS SAM 템플릿 섹션입니다.

Resources: MyApi: Type: AWS::Serverless::HttpApi Properties: StageName: Prod Auth: DefaultAuthorizer: MyLambdaRequestAuthorizer Authorizers: MyLambdaRequestAuthorizer: FunctionArn: !GetAtt MyAuthFunction.Arn FunctionInvokeRole: !GetAtt MyAuthFunctionRole.Arn Identity: Headers: - Authorization AuthorizerPayloadFormatVersion: 2.0 EnableSimpleResponses: true MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Handler: index.handler Runtime: nodejs12.x Events: GetRoot: Type: HttpApi Properties: ApiId: !Ref MyApi Path: / Method: get PayloadFormatVersion: "2.0" MyAuthFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Handler: authorizer.handler Runtime: nodejs12.x