Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 25 additions & 54 deletions kendra_retriever_samples/kendra-docs-index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
##and index the crawled documents.
##The output of the CloudFormation template shows the Kendra index id and the AWS region it was created in.
##It takes about 30 minutes to create an Amazon Kendra index and about 15 minutes more to crawl and index
##the content of these webpages to the index. Hence you might need to wait for about 45 minutes after
##the content of these webpages to the index. Hence, you might need to wait for about 45 minutes after
##launching the CloudFormation stack
Resources:
##Create the Role needed to create a Kendra Index
Expand Down Expand Up @@ -34,37 +34,23 @@ Resources:
Resource: '*'
Action: 'logs:DescribeLogGroups'
- Effect: Allow
Resource: !Sub
- 'arn:aws:logs:${region}:${account}:log-group:/aws/kendra/*'
- region: !Ref 'AWS::Region'
account: !Ref 'AWS::AccountId'
Action: 'logs:CreateLogGroup'
Resource: !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/kendra/*'
Action:
- 'logs:CreateLogGroup'
- Effect: Allow
Resource: !Sub
- 'arn:aws:logs:${region}:${account}:log-group:/aws/kendra/*:log-stream:*'
- region: !Ref 'AWS::Region'
account: !Ref 'AWS::AccountId'
Action:
Resource: !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/kendra/*:log-stream:*'
Action:
- 'logs:DescribeLogStreams'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
PolicyName: !Join
- ''
- - !Ref 'AWS::StackName'
- '-DocsKendraIndexPolicy'
RoleName: !Join
- ''
- - !Ref 'AWS::StackName'
- '-DocsKendraIndexRole'

PolicyName: !Sub '${AWS::StackName}-DocsKendraIndexPolicy'
RoleName: !Sub '${AWS::StackName}-DocsKendraIndexRole'

##Create the Kendra Index
DocsKendraIndex:
Type: 'AWS::Kendra::Index'
Properties:
Name: !Join
- ''
- - !Ref 'AWS::StackName'
- '-Index'
Name: !Sub '${AWS::StackName}-Index'
Edition: 'DEVELOPER_EDITION'
RoleArn: !GetAtt KendraIndexRole.Arn

Expand All @@ -85,28 +71,18 @@ Resources:
Version: 2012-10-17
Statement:
- Effect: Allow
Resource: !Sub
- 'arn:aws:kendra:${region}:${account}:index/${index}'
- region: !Ref 'AWS::Region'
account: !Ref 'AWS::AccountId'
index: !GetAtt DocsKendraIndex.Id
Resource: !Sub 'arn:aws:kendra:${AWS::Region}:${AWS::AccountId}:index/${DocsKendraIndex.Id}'
Action:
- 'kendra:BatchPutDocument'
- 'kendra:BatchDeleteDocument'
PolicyName: !Join
- ''
- - !Ref 'AWS::StackName'
- '-DocsDSPolicy'
RoleName: !Join
- ''
- - !Ref 'AWS::StackName'
- '-DocsDSRole'

PolicyName: !Sub '${AWS::StackName}-DocsDSPolicy'
RoleName: !Sub '${AWS::StackName}-DocsDSRole'

#Docs Data Source
KendraDocsDS:
Type: 'AWS::Kendra::DataSource'
Properties:
DataSourceConfiguration:
Properties:
DataSourceConfiguration:
WebCrawlerConfiguration:
UrlInclusionPatterns:
- '.*https://docs.aws.amazon.com/lex/.*'
Expand All @@ -122,9 +98,10 @@ Resources:
Name: 'KendraDocsDS'
RoleArn: !GetAtt KendraDSRole.Arn
Type: 'WEBCRAWLER'



DataSourceSyncLambdaRole:
Type: AWS::IAM::Role
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Expand All @@ -140,34 +117,28 @@ Resources:
Version: 2012-10-17
Statement:
- Effect: Allow
Resource: !Sub
- 'arn:aws:kendra:${region}:${account}:index/${index}*'
- region: !Ref 'AWS::Region'
account: !Ref 'AWS::AccountId'
index: !GetAtt DocsKendraIndex.Id
Resource: !Sub 'arn:aws:kendra:${AWS::Region}:${AWS::AccountId}:index/${DocsKendraIndex.Id}*'
Action:
- 'kendra:*'
PolicyName: DataSourceSyncLambdaPolicy

DataSourceSyncLambda:
Type: AWS::Lambda::Function
Type: 'AWS::Lambda::Function'
Properties:
Handler: index.lambda_handler
Runtime: python3.8
Role: !GetAtt 'DataSourceSyncLambdaRole.Arn'
Role: !GetAtt DataSourceSyncLambdaRole.Arn
Timeout: 900
MemorySize: 1024
Code:
ZipFile: |

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0

import json
import logging
import boto3
import cfnresponse
import random
import os

logger = logging.getLogger()
Expand All @@ -194,9 +165,9 @@ Resources:
Variables:
INDEX_ID: !GetAtt DocsKendraIndex.Id
DS_ID: !GetAtt KendraDocsDS.Id

DataSourceSync:
Type: Custom::DataSourceSync
Type: 'Custom::DataSourceSync'
DependsOn:
- DocsKendraIndex
- KendraDocsDS
Expand Down