Retrieving data from a customer's Amazon Q index as a data accessor using the SearchRelevantContent API
With valid configuration parameters from the customer, the ISV can use the
SearchRelevantContent
API operation to retrieve user-specific
content from the customer's Amazon Q index.
The following are examples of how to use either Auth Code or Trusted Token Issuer based authentication (TTI) to complete this task:
The following tabs provide a procedure to boost document attributes using the console and code examples for the AWS CLI.
- Auth code
-
Use the Authentication code method to retrieve user-specific content from the customer's Amazon Q index.
-
The Amazon Q index customer's end user will login to the ISV's application using the existing user login flow.
Note
The ISV doesn't need to change their existing login flow.
-
After the end user successfully logs in, the ISV instructs the user to authenticate to their Amazon Q index through their OIDC providers. For more information, see Creating an Amazon Q Business application using AWS IAM Identity Center.
-
https://oidc.${idc_region}.amazonaws.com/authorize?response_type=code&redirect_uri=${isv_redirect_url}&state={oauth_state}&client_id=${idc_application_arn}
-
isv_redirect_uri
— This is the redirect URL that's registered at the ISV registration process. For more information, see Information to be provided to the Amazon Q Business team. -
oauth_state
— This random string prevents cross-site request forgery (CSRF) attack. For more detail about state parameters in oauth, see Prevent Attacks and Redirect Users with OAuth 2.0 State Parametersin the auth by Okta guide. -
idc_application_arn
— This is the Amazon Q Business DataAccessor IAM Identity Center application ID that's provided by the customer to the ISV.
-
-
The end user logs in using the method configured by the customer's Amazon Q administrator. For example, the user's company SSO.
-
The ISV application receives an auth code in their redirect URL.
-
The ISV application calls the
CreateTokenWithIAM
API operation to get a token with an authorization code. The ISV needs to use the AWS Identity and Access Management (IAM) role that they created during the onboarding process withtenantId
information in the tags like the following:aws sts assume-role \ --role-arn ${your_iam_role} \ --role-session-name test-session \ --tags Key=qbusiness-dataaccessor:ExternalId,Value=${isv tenantId} aws sso-oidc create-token-with-iam --client-id "${idc_application_arn}" \ --redirect-uri "{your_redirect_uri}" \ --grant-type "authorization_code" \ --code "${CODE}" --region ${idc_region}
-
Get the
idToken
field from the response ofCreateTokenWithIAM
. Then, decode theidToken
and extract"sts:identity_context"
field from it.Using command line:
export ID_TOKEN_I = "${response_json_of_create-token-with-iam}" export ID_CONTEXT=`jq -R 'split(".") | .[1] | @base64d | fromjson' <<< "$ID_TOKEN_I" | jq -r '."sts:identity_context"'` echo "ID_CONTEXT=$ID_CONTEXT\n"
Using Python:
import json import base64 body = "${response_json_of_create-token-with-iam}" body_json = base64.urlsafe_b64decode(body.split(".")[1] + '==') data = json.loads(body_json) print(f"{data['sts:identintity_context']}")
-
Call the AssumeRole API with the extracted
sts:identity_context
and the ISVtenantId
information.aws sts assume-role \ --role-arn ${your_iam_role} \ --role-session-name test-session \ --provided-contexts '[{"ProviderArn": "arn:aws:iam::aws:contextProvider/IdentityCenter", "ContextAssertion": "${value from sts:identity_context}"}]' \ --tags Key=qbusiness-dataaccessor:ExternalId,Value=${isv tenantId}
-
Use the AWS Sig V4 credentials returned from the previous step to call
SearchRelevantContent
API.aws qbusiness search-relevant-content \ --application-id ${qbusiness_application_id} \ --query-text "What is Amazon Q?" \ --content-source '{"retriever": {"retrieverId": "${retriever_id}"}}'
-
- TTI
-
Use the Trusted Token Issuer based authentication (TTI) method to retrieve user-specific content from the customer's Amazon Q index.
-
The Amazon Q index customer's end user will log in to the ISV's application using the existing user login flow.
-
After the end user successfully logs in, ISV issues a token for the end user using the OIDC client as audience, provided during the onboarding process.
-
The ISV application calls the
CreateTokenWithIAM
API operation with the token from step 2. The ISV needs to use the AWS Identity and Access Management (IAM) role that they created during the onboarding process withtenantId
information in the tags like the following:aws sts assume-role \ --role-arn ${your_iam_role} \ --role-session-name test-session \ --tags Key=qbusiness-dataaccessor:ExternalId,Value=${isv tenantId} aws sso-oidc create-token-with-iam --client-id "${idc_application_arn}" \ --grant-type "urn:ietf:params:oauth:grant-type:jwt-bearer" \ --assertion "${isv token generated using oidc client provided during onboarding}" --region ${idc_region}
-
Retrieve the
idToken
field from the response ofCreateTokenWithIAM
. Then, decode theidToken
and extractsts:identity_context
field from it.-
Using command line:
export ID_TOKEN_I = "${response_json_of_create-token-with-iam}" export ID_CONTEXT=`jq -R 'split(".") | .[1] | @base64d | fromjson' <<< "$ID_TOKEN_I" | jq -r '."sts:identity_context"'` echo "ID_CONTEXT=$ID_CONTEXT\n"
-
Using Python:
import json import base64 body = "${response_json_of_create-token-with-iam}" body_json = base64.urlsafe_b64decode(body.split(".")[1] + '==') data = json.loads(body_json) print(f"{data['sts:identintity_context']}")
-
-
Call the
AssumeRole
API with the extractedsts:identity_context
and the ISVtenantId
information.aws sts assume-role \ --role-arn ${your_iam_role} \ --role-session-name test-session \ --provided-contexts '[{"ProviderArn": "arn:aws:iam::aws:contextProvider/IdentityCenter", "ContextAssertion": "${value from sts:identity_context}"}]' \ --tags Key=qbusiness-dataaccessor:ExternalId,Value=${isv tenantId}
Use the AWS Sig V4 credentials returned from the previous step to call
SearchRelevantContent
API.aws qbusiness search-relevant-content \ --application-id ${qbusiness_application_id} \ --query-text "What is Amazon Q?" \ --content-source '{"retriever": {"retrieverId": "${retriever_id}"}}'
-