← AI Practitioner study path

Practice in your account · 30 min

Who called the model and what did they ask?

In this lab you will turn on Amazon Bedrock model invocation logging, make two calls to a model and find in AWS CloudTrail who made the call and in CloudWatch Logs what they asked.

When someone calls an Amazon Bedrock model, two different services store data about that call. AWS CloudTrail records who made it, at what time and from which , but it doesn't record the text that was sent to the model. That text, the , is stored by Amazon Bedrock model invocation logging, which is off by default and which you have to turn on. Invoking a model means calling it, so this log is the list of calls with what was asked and what the model answered. For example, if an employee at a store asks the model how to process a return, CloudTrail records that she called the model at ten in the morning, and invocation logging stores her question and the answer.

This difference matters when a company has to account for what happened in a . For example, if a company sets up a chatbot to answer its employees and the legal team asks what someone wrote to it on Tuesday, CloudTrail doesn't have that answer, and invocation logging only has it if it was turned on before Tuesday.

Governance services and the question each one answers

Governance is the set of rules a company uses to control what happens in its account, and auditing is checking afterward whether those rules were followed. Each AWS service for governance and auditing answers a different question. AWS CloudTrail answers who did what, when and from where. Next to it are AWS Config, which answers how each resource is configured and when it changed, and AWS Artifact, which answers where to download AWS compliance reports. A resource is anything you create in your account, and a compliance report is a document that shows AWS follows a security standard. For example, if an auditor asks a bank for proof that AWS meets a certain standard, the bank downloads it from AWS Artifact, and if the auditor asks who deleted a file yesterday, the answer is in CloudTrail.

Where do you find it?

0 of 4

Tap the place where each piece of data from a call to a model is stored.

  1. Which identity called the model

  2. The exact text of the prompt

  3. The time and source IP of the call

  4. The response the model gave

Before you start

This lab uses the us-east-2 Region. Invocation logging is configured in each Region separately, so if you change Regions in the middle of the lab, you won't see the . For example, if you turn on logging in us-east-2 and then call the model in us-east-1, that call isn't logged.

The model is Amazon Nova Lite, which is invoked within us-east-2. Logging only captures calls that go through the bedrock-runtime endpoint, which is the internet address calls to the models are sent to, and with this model both the playground and the AWS CLI go through it. The playground is the chat screen in the Bedrock console, and the AWS CLI is the program that sends written commands to AWS.

The lab's creates two resources: a log group, which keeps events for 3 days, and a that allows writing to that group. That role can only be assumed by Amazon Bedrock, from your account and your Region. Assuming a role means using its permissions, so Bedrock can write to your log group and no other service or account can do so with that role. For example, each time you call the model, Bedrock uses that role to leave a new entry in the log group.

Turn on logging and call the model

  1. In the CloudFormation console, choose Create stack, With new resources (standard) and Upload a template file. Upload [lab08a-registro-invocaciones.yaml](/roadmaps/plantillas/lab08a-registro-invocaciones.yaml) and enter cloudpath-aif5-registro as the stack name. Select the check box that acknowledges that the template creates IAM resources and choose Submit.
  2. When the stack reaches CREATE_COMPLETE, copy the GrupoDeLogs and Rol outputs.
  3. Open the Amazon Bedrock console. In the left panel choose Settings and turn on Model invocation logging.
  4. Select only Text as the modality. For the destination choose only CloudWatch Logs. Choose the log group and the role from step 2, and save.
  5. In the chat playground, choose Amazon Nova Lite and send two messages: - Resume en una línea qué es Amazon Bedrock. - Mi correo es ana@example.com, ¿lo puedes repetir?

In steps 1 and 2, CloudFormation creates the stack, which is the group of resources that come out of the template, and CREATE_COMPLETE means it finished creating them. The check box in step 1 confirms that you accept the template creating the role, because roles are part of IAM, the AWS service that manages who can do what in your account. In step 4, the modality is the type of content that gets logged; with Text, logging stores the written messages and not images. For example, the two messages in step 5 are text, so both are logged.

Find each piece of data in its place

In this part you'll open the two places where your calls ended up and check what each one stores. For example, you'll find the time of your first message in CloudTrail, and the text of that same message in CloudWatch Logs.

  1. Open CloudTrail, Event history. Filter by the event source bedrock.amazonaws.com and look for a Converse or InvokeModel event or its streaming version (write down which one appears). Open it and find userIdentity, eventTime and sourceIPAddress. The text of your prompt doesn't appear in the event.
  2. Open CloudWatch, Log groups, the group from step 2, and the aws/bedrock/modelinvocations stream. Open an event and find the model ID, the prompt and the response. The email from the second message is there in plain text.

Streaming, in step 6, is the way of calling the model where the response arrives in pieces while it's being written, and that's why it has its own event name. Step 7 shows that logging stores everything your users write, including their personal data, and that it stores it in . AWS also warns that, if you had a guardrail, the content the guardrail blocks also appears in plain text in this log.

To handle that, a company can limit who reads the log group, mask the data with a CloudWatch Logs data protection policy or stop logging certain data. Masking a piece of data means replacing it with a marker that hides it. For example, with a data protection policy, whoever opens the log would see a marker instead of ana@example.com.

What do you give the legal team?

How to know you're done

From CloudShell you can check the three parts of the lab with these commands:

aws bedrock get-model-invocation-logging-configuration --region us-east-2

aws cloudtrail lookup-events --region us-east-2 \
  --lookup-attributes AttributeKey=EventSource,AttributeValue=bedrock.amazonaws.com \
  --max-results 5 --query "Events[].[EventName,EventTime,Username]" --output table

aws logs tail <GrupoDeLogs> --region us-east-2 --since 1h

Before you run them, replace <GrupoDeLogs> with the output you copied in step 2. The first command shows the logging configuration with your log group, the second lists the calls to the model and who made them, and the third shows the log events with the text of your two messages. For example, in the output of the third one you should find the sentence Resume en una línea qué es Amazon Bedrock. exactly as you wrote it.

Delete what you created

  1. In Bedrock, Settings, turn off model invocation logging and save. Do this before you delete the stack, so that Bedrock doesn't try to write with a role that no longer exists.
  2. In CloudFormation, delete the cloudpath-aif5-registro stack. The log group and the role are deleted with it.

CloudTrail events stay in your account and you don't have to do anything with them, because the event history keeps the last 90 days and doesn't charge. For example, if you open the history again next week, today's calls will still show up there.

If your account is a new experience account

Bedrock, CloudTrail, CloudWatch Logs, CloudFormation and IAM are on the free plan, and the new experience policy allows cloudtrail:LookupEvents. In a project, IAM users only have , but that doesn't affect this lab, because the template creates a role for the Bedrock service and not a user.

If in your project the Bedrock settings don't show the option to turn on logging, do the lab up to step 6. That way you will see the CloudTrail part, even though you miss the invocation logging part.

Next

  • cloud path practice exams: /examenes?lang=en