Mercurial > public > tweet-analysis
changeset 2:561bc303784f
customize api gateway resources
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Thu, 16 Sep 2021 11:36:21 +0200 |
parents | 0277e7fc0f0a |
children | 5c36f51105c2 |
files | template.yaml |
diffstat | 1 files changed, 90 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/template.yaml Thu Sep 16 09:38:07 2021 +0200 +++ b/template.yaml Thu Sep 16 11:36:21 2021 +0200 @@ -11,10 +11,77 @@ Api: Auth: ApiKeyRequired: true - UsagePlan: - CreateUsagePlan: PER_API Resources: + ## + ### START API GATEWAY CONFIGURATION ### + ## + + # Create Api version v1 + V1Stage: + Type: AWS::ApiGateway::Stage + Properties: + DeploymentId: !Ref V1StageDeployment + Description: Api version 1 + RestApiId: !Ref ServerlessRestApi + StageName: v1 + Tags: + - Key: "application-id" + Value: "tweet-analysis" + - Key: "Name" + Value: "tweet-analysis::rest-api::v1" + + # Deploy Api version 1 + V1StageDeployment: + Type: AWS::ApiGateway::Deployment + Properties: + Description: Deployment of Api version 1 + RestApiId: !Ref ServerlessRestApi + + # Create usage plan + PaidUsagePlan: + Type: AWS::ApiGateway::UsagePlan + Properties: + ApiStages: + - ApiId: !Ref ServerlessRestApi + Stage: !Ref V1Stage + Description: Api usage plan + Quota: + Limit: 10000 + Period: MONTH + Throttle: + BurstLimit: 100 + RateLimit: 20 + UsagePlanName: PaidUsagePlan + Tags: + - Key: "application-id" + Value: "tweet-analysis" + - Key: "Name" + Value: "tweet-analysis::rest-api::paid-usage-plan" + + # Create Api key + PaidApiKey: + Type: AWS::ApiGateway::ApiKey + Properties: + Description: Api key for paid usage plan + Enabled: true + StageKeys: + - RestApiId: !Ref ServerlessRestApi + StageName: !Ref V1Stage + Tags: + - Key: "application-id" + Value: "tweet-analysis" + - Key: "Name" + Value: "tweet-analysis::rest-api::key" + + # Attach the created api key to the usage plan + PaidUsagePlanKey: + Type: AWS::ApiGateway::UsagePlanKey + Properties: + KeyId: !Ref PaidApiKey + KeyType: API_KEY + UsagePlanId: !Ref PaidUsagePlan + # Create custom domain in Api Gateway Domain: Type: AWS::ApiGateway::DomainName @@ -31,6 +98,14 @@ - Key: "Name" Value: "tweet-analysis::api-custom-domain" + ## + ### END API CONFIGURATION ### + ## + + ## + ### START DOMAIN CONFIGURATION ### + ## + # Create domain SSL certificate DomainCertificate: Type: AWS::CertificateManager::Certificate @@ -64,7 +139,15 @@ Properties: DomainName: !Ref Domain RestApiId: !Ref ServerlessRestApi - Stage: Prod + Stage: v1 + + ## + ### END DOMAIN CONFIGURATION ### + ## + + ## + ### START FUNCTION CONFIGURATION ### + ## # Define lambda functions GetTweetSentimentFunction: @@ -82,3 +165,7 @@ Properties: Path: /sentiment Method: get + + ## + ### END FUNCTION CONFIGURATION ### + ##