Mercurial > public > tweet-analysis
diff template.yaml @ 1:0277e7fc0f0a
first successful sam deploy
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Thu, 16 Sep 2021 09:38:07 +0200 |
parents | cea9500dca25 |
children | 561bc303784f |
line wrap: on
line diff
--- a/template.yaml Tue Sep 14 17:46:04 2021 +0200 +++ b/template.yaml Thu Sep 16 09:38:07 2021 +0200 @@ -1,39 +1,84 @@ AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 -Description: > - tweet-analysis +Description: Fetch & analyse tweets using AWS Comprehend - Sample SAM Template for tweet-analysis - -# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst +# Global Settings Globals: Function: Timeout: 3 + Tags: + application-id: "tweet-analysis" + Api: + Auth: + ApiKeyRequired: true + UsagePlan: + CreateUsagePlan: PER_API Resources: - HelloWorldFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction + # Create custom domain in Api Gateway + Domain: + Type: AWS::ApiGateway::DomainName Properties: - CodeUri: hello_world/ - Handler: app.lambda_handler - Runtime: python3.9 - Events: - HelloWorld: - Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api - Properties: - Path: /hello - Method: get + RegionalCertificateArn: !Ref DomainCertificate + DomainName: tweet-analysis.dennistech.io + SecurityPolicy: TLS_1_2 + EndpointConfiguration: + Types: + - REGIONAL + Tags: + - Key: "application-id" + Value: "tweet-analysis" + - Key: "Name" + Value: "tweet-analysis::api-custom-domain" + + # Create domain SSL certificate + DomainCertificate: + Type: AWS::CertificateManager::Certificate + Properties: + DomainName: tweet-analysis.dennistech.io + ValidationMethod: DNS + DomainValidationOptions: + - DomainName: tweet-analysis.dennistech.io + HostedZoneId: Z0937998E3C5GEK4NHO9 + Tags: + - Key: "application-id" + Value: "tweet-analysis" + - Key: "Name" + Value: "tweet-analysis::certificate::dennistech.io" -Outputs: - # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function - # Find out more about other implicit resources you can reference within SAM - # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api - HelloWorldApi: - Description: "API Gateway endpoint URL for Prod stage for Hello World function" - Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/" - HelloWorldFunction: - Description: "Hello World Lambda Function ARN" - Value: !GetAtt HelloWorldFunction.Arn - HelloWorldFunctionIamRole: - Description: "Implicit IAM Role created for Hello World function" - Value: !GetAtt HelloWorldFunctionRole.Arn + # Map domain to the regional domain generated by Api Gateway + DomainMapping: + Type: AWS::Route53::RecordSet + Properties: + HostedZoneId: Z0937998E3C5GEK4NHO9 + Name: tweet-analysis.dennistech.io + Type: A + AliasTarget: + DNSName: !GetAtt Domain.RegionalDomainName + EvaluateTargetHealth: true + HostedZoneId: !GetAtt Domain.RegionalHostedZoneId + + # Map paths from your domain name to your API stages + PathMapping: + Type: AWS::ApiGateway::BasePathMapping + Properties: + DomainName: !Ref Domain + RestApiId: !Ref ServerlessRestApi + Stage: Prod + + # Define lambda functions + GetTweetSentimentFunction: + Type: AWS::Serverless::Function + Properties: + Description: Fetch tweets and analyse sentiment using AWS Comprehend + CodeUri: src/ + Handler: handlers/sentiment.get_tweet_sentiment + Runtime: python3.9 + Tags: + Name: "tweet-analysis::get-tweet-sentiment-function" + Events: + CallGetTweetSentiment: + Type: Api + Properties: + Path: /sentiment + Method: get