AWSTemplateFormatVersion: "2010-09-09" Parameters: ChatBotDatabaseLoaderArn: Description: "The ARN for the validation Lambda" Type: String BlogURL: Default: "https://aws.amazon.com/blogs/database/category/database/amazon-neptune/" Description: "The blog url" Type: String Resources: # Upload Layers CRHelperLayer: Type: AWS::Lambda::LayerVersion Properties: CompatibleRuntimes: - python3.7 - python3.8 Content: S3Bucket: Fn::Join: - '' - - 'aws-neptune-customer-samples-' - Ref: AWS::Region S3Key: chatbot-blog/crhelper-layer.zip Description: Python 3.7 Lambda Layer with crhelper library for creating custom CFN resources LayerName: crhelper PillowLayer: Type: AWS::Lambda::LayerVersion Properties: CompatibleRuntimes: - python3.7 - python3.8 Content: S3Bucket: Fn::Join: - '' - - 'aws-neptune-customer-samples-' - Ref: AWS::Region S3Key: chatbot-blog/Pillow.zip Description: Python 3.7 Lambda Layer with aPillow LayerName: Pillow BlogParserLayer: Type: AWS::Lambda::LayerVersion Properties: CompatibleRuntimes: - python3.7 - python3.8 Content: S3Bucket: Fn::Join: - '' - - 'aws-neptune-customer-samples-' - Ref: AWS::Region S3Key: chatbot-blog/blogparser.zip Description: Python 3.7 Lambda Layer with boto3, beautifulsoup, and requests LayerName: blog-parser #Create Lambda Role BlogParserRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - lambda.amazonaws.com Action: - sts:AssumeRole ManagedPolicyArns: - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" Policies: - PolicyName: blog-chatbot-blogparser PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - comprehend:BatchDetectEntities Resource: "*" - PolicyName: blog-chatbot-blogparser-lambda-role PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - lambda:InvokeFunction Resource: !Ref ChatBotDatabaseLoaderArn # Upload Custom Deploy Function BlogParserLambda: Type: AWS::Lambda::Function DependsOn: - CRHelperLayer - PillowLayer - BlogParserLayer - BlogParserRole Properties: Code: S3Bucket: Fn::Join: - '' - - 'aws-neptune-customer-samples-' - Ref: AWS::Region S3Key: chatbot-blog/blog-chatbot-blog-parser.zip Description: Custom CFN Resource for parsing the blogs FunctionName: chatbot-blog-parser Handler: lambda_function.lambda_handler Layers: - !Ref CRHelperLayer - !Ref PillowLayer - !Ref BlogParserLayer Role: !GetAtt BlogParserRole.Arn Runtime: python3.7 Timeout: 600 #Call Custom Function BlogParserResource: Type: "Custom::BlogParserLambda" DependsOn: - BlogParserLambda Properties: ServiceToken: !GetAtt BlogParserLambda.Arn URL: !Ref BlogURL Outputs: Sum: Value: !GetAtt BlogParserResource.Status