Get startedGet started for free

Generating text in Bedrock

Building on your success with Claude, the specialty-coffee company now wants to roll out AI-assisted writing to their marketing department. They're launching a New Year campaign and need compelling subject lines: it's time to generate some catchy options with Bedrock!

The boto3 and json libraries have been pre-imported. The prompt is already provided as: "Write an engaging email subject line for a coffee company's New Year marketing campaign".

This exercise is part of the course

Introduction to Amazon Bedrock

View Course

Exercise instructions

  • Set the keys in the dictionary to complete the "messages" list for the Nova model.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

bedrock = boto3.client('bedrock-runtime', region_name='us-east-1')

# Set the dictionary keys
message = {"____": "user",
           "____": [{"text": prompt}]}

nova_response = bedrock.invoke_model(modelId='amazon.nova-lite-v1:0', body=json.dumps({"messages": [message]}))

print(json.loads(nova_response.get("body").read().decode())["output"]["message"]["content"][0]["text"])
Edit and Run Code