AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: API using NodeJS and Typescript
Parameters:
APIName:
Type: String
Description: The name of the Test API
MinLength: 3
MaxLength: 20
AllowedPattern: "^[a-zA-Z][a-zA-Z0-9_]*$"
Default: TestAPI
CognitoUserPoolName:
Type: String
CognitoUserPoolClientName:
Type: String
IdentityPoolName:
Type: String
AllowOrigin:
Type: String
Default: "'*'"
Globals:
Function:
Runtime: nodejs12.x
Timeout: 10
Resources:
ApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref NodeEnv
DefinitionBody:
Auth:
Authorizers:
CognitoAuthorizer:
UserPoolArn: !GetAtt CognitoUserPool.Arn
Cors:
AllowOrigin: !Ref AllowOrigin
AllowMethods: "'*'"
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: !Ref CognitoUserPoolName
CognitoUserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
ExplicitAuthFlows:
- ADMIN_NO_SRP_AUTH
UserPoolId: !Ref CognitoUserPool
ClientName: !Ref CognitoUserPoolClientName
CognitoIdentityPool:
Type: AWS::Cognito::IdentityPool
Properties:
IdentityPoolName: !Ref IdentityPoolName
AllowUnauthenticatedIdentities: False
CognitoIdentityProviders:
- ClientId: !Ref CognitoUserPoolClient
ProviderName:
Fn::GetAtt: [CognitoUserPool, ProviderName]
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./handler.zip
Handler: hello.handler
Events:
HelloWorld:
Type: Api
Properties:
RestApiId: !Ref ApiGateway
Path: /hello
Method: get
Outputs:
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
cognito で認証を行う場合は、こんな感じの CFn で動くのではないかと思います。