<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: NaDia</title>
    <description>The latest articles on Forem by NaDia (@ronakreyhani).</description>
    <link>https://forem.com/ronakreyhani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F293443%2Fcef3e6d4-fa0f-4004-9d2d-c2d97632f17b.jpeg</url>
      <title>Forem: NaDia</title>
      <link>https://forem.com/ronakreyhani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ronakreyhani"/>
    <language>en</language>
    <item>
      <title>Building Enterprise-Ready AI Agents: Key Takeaways from AWS re:Invent 2025</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Thu, 04 Dec 2025 23:58:39 +0000</pubDate>
      <link>https://forem.com/aws-heroes/building-enterprise-ready-ai-agents-key-takeaways-from-aws-reinvent-2025-57dd</link>
      <guid>https://forem.com/aws-heroes/building-enterprise-ready-ai-agents-key-takeaways-from-aws-reinvent-2025-57dd</guid>
      <description>&lt;p&gt;If you didn’t have a chance to attend AWS re:Invent this year, don’t worry. While key sessions will be available online, here is a concise summary of one of the standout sessions I attended at #reInvent2025.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;All credit to AWS and the presenters of this session.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“Agents in Enterprise: Best Practices With Amazon Bedrock AgentCore”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Moving from POC to production with AI agents is rarely straightforward. Challenges arise around accuracy, scalability, latency, infrastructure costs, model inference expenses, security, observability, and memory retention. Many teams jump straight into building agents without planning where to start and how to operationalize an agentic platform at enterprise scale.&lt;/p&gt;

&lt;p&gt;This session distilled nine core best practices for building robust, production-ready Agentic systems.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;🔹 Top 9 Best Practices for Agentic Platform Success&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Start Small &amp;amp; Work Backwards&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Agent development is an interactive journey, you can adopt new models, add tools and improve prompts. Define what the agent should and shouldn't do, with clear and complete definitions and expected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Implement Observability from Day One&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Agents are OTEL compatible. Enable full trace-level visibility and observability dashboards early, not later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Define Your Tooling Strategy Explicitly&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Document tool requirements, input/output schemas, and error-handling logic.&lt;br&gt;
Reducing ambiguity reduces tokens and costs. Leverage existing MCP servers and expose tools via the MCP server and show integration patterns with code samples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Automate Evaluation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Define technical and business metrics early and include business users in the evaluation loop. Test across diverse user intents including misuse patterns to strengthen resilience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Avoid the “One Agent With 100 Tools” Anti-Pattern&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use multi-agent architectures with clear roles, orchestrated workflows, and shared context.&lt;br&gt;
Monitor how agents collaborate and escalate tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Establish Proper Memory Boundaries&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Plan for:&lt;br&gt;
    •short-term session memory&lt;br&gt;
    •long-term personalised memory&lt;/p&gt;

&lt;p&gt;Isolate user context and enforce security policies at execution. Host agents and tools separately for compliance and performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Cost vs. Value: Be Pragmatic&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If deterministic code works reliably, use it. Reserve agent reasoning for tasks that actually require reasoning rather than forcing agents into everything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Test Relentlessly&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rerun evaluation after every update.&lt;br&gt;
Use:&lt;br&gt;
    • A/B deployments&lt;br&gt;
    • drift monitoring&lt;br&gt;
    • automated rollback&lt;/p&gt;

&lt;p&gt;Production monitoring is not optional, it’s mandatory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. Scale Through Platform Standardisation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Deploying agents to production is step one, not the finish line.&lt;br&gt;
To scale safely:&lt;br&gt;
    •Build a central platform team for enablement&lt;br&gt;
    •Standardise governance, observability, and tooling&lt;br&gt;
    •Promote cross-team collaboration to avoid duplicated effort&lt;/p&gt;

&lt;p&gt;The session showcased an excellent org model outlining split responsibilities between platform vs. use-case teams. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpy7h88p0mfeloim52ytk.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpy7h88p0mfeloim52ytk.jpeg" alt="platform vs. Use-case" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So Where Does AgentCore Fit In?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1vpx0okx4kika3rvdlyl.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1vpx0okx4kika3rvdlyl.jpeg" alt="AgentCore" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Amazon Bedrock AgentCore Operationalises these best practices out-of-the-box, enabling enterprise-grade agent development at scale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Capabilities Overview:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Runtime:
Supports any agent framework, prompt schema, tool routing &amp;amp; context injection.&lt;/li&gt;
&lt;li&gt;MCP &amp;amp; A2A Compatible:
Seamless interoperability between agents and MCP servers&lt;/li&gt;
&lt;li&gt;Memory Layer:
Persistent and session-based memory for personalisation.&lt;/li&gt;
&lt;li&gt;Tooling:
Catalog + governance + reuse capability. Define MCP servers, use AgentCore Browser Tooling for safe web navigation and data extraction. And Code Interpreter to execute code securely in isolation when needed.&lt;/li&gt;
&lt;li&gt;Identity &amp;amp; Access Control:
Ensures the right agent accesses the right tool securely.&lt;/li&gt;
&lt;li&gt;Policy Enforcement:
Applies organisational rules &amp;amp; compliance guardrails.&lt;/li&gt;
&lt;li&gt;Evaluation Engine:
Built-in testing and performance assessment with customisable metrics.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Final Takeaway&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This session perfectly reinforced that building agents is not just about prompting, it’s about engineering:&lt;br&gt;
    • platform standardisation&lt;br&gt;
    • tooling governance&lt;br&gt;
    • secure orchestration&lt;br&gt;
    • memory boundaries&lt;br&gt;
    • rigorous evaluation&lt;br&gt;
    • enterprise scalability&lt;/p&gt;

&lt;p&gt;AgentCore becomes the backbone that enables all of this, from experimentation to full-scale production with observability, governance, and operational safety built in.&lt;/p&gt;

</description>
      <category>reinvent2025</category>
      <category>agenticaai</category>
      <category>agentcore</category>
      <category>amazonbedrock</category>
    </item>
    <item>
      <title>Amazon Bedrock Blueprint: Architecting AI Projects with Amazon Bedrock</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Mon, 29 Apr 2024 12:57:29 +0000</pubDate>
      <link>https://forem.com/aws-builders/amazon-bedrock-blueprint-architecting-ai-projects-with-amazon-bedrock-4686</link>
      <guid>https://forem.com/aws-builders/amazon-bedrock-blueprint-architecting-ai-projects-with-amazon-bedrock-4686</guid>
      <description>&lt;h3&gt;
  
  
  Initial Words
&lt;/h3&gt;

&lt;p&gt;If you're actively involved in the AI field and utilise AWS Cloud services, chances are you've explored Amazon Bedrock to enhance your applications with AI capabilities. Even if you haven't directly worked with it, you've likely heard about the advanced Foundational Models that Amazon Bedrock offers. In this blog post, I'll provide a comprehensive introduction to Amazon Bedrock components and delve into common workflows for integrating Amazon Bedrock into Generative AI projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Amazon Bedrock Components
&lt;/h3&gt;

&lt;p&gt;Exploring various articles on Amazon Bedrock will give you enough information about its nature. As you may be aware, Amazon Bedrock offers a quick serverless experience, granting access to an extensive array of Foundational Models. Its unified API is especially noteworthy, as it streamlines the integration of these diverse models into your system.&lt;br&gt;
However, the question remains: how does Amazon Bedrock achieve this? What components does it comprise that set it apart from other AI platforms or services? This is the exploration we aim to undertake in this section.&lt;/p&gt;

&lt;h4&gt;
  
  
  Foundational Models
&lt;/h4&gt;

&lt;p&gt;Yes, Amazon Bedrock offers a wide range of Foundational Models like AI21 Labs, Anthropic, Cohere, Meta, Mistral AI, Stability AI, and Amazon. But what's the advantage of using these models within Bedrock? You're not restricted to just one specific model. Bedrock's API makes it easy to integrate these models. If you decide to switch from Mistral to Cohere models, all you need to do is change the model ID within your "&lt;code&gt;InvokeModel&lt;/code&gt;" API from Bedrock. Additionally, if your system needs to integrate with multiple models, Bedrock's API layer allows you to invoke as many models as you need in parallel but completely isolated from each other.&lt;/p&gt;

&lt;h4&gt;
  
  
  Knowledge Base
&lt;/h4&gt;

&lt;p&gt;Using Foundational Models alone has limitations. However, there are effective approaches to overcome these limitations, which I'll discuss in the "&lt;code&gt;AI Workflows With Bedrock&lt;/code&gt;" section. It's still important to understand these limitations such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Outdated information&lt;/li&gt;
&lt;li&gt;Lack of knowledge on your data set.&lt;/li&gt;
&lt;li&gt;Lack of transparency on how they arrived at specific answers.&lt;/li&gt;
&lt;li&gt;Hallucination&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm sure you're aware that Foundational Models are trained on vast amounts of data, but there's no guarantee they're always up to date with the latest information. These models provide answers without providing the source links for the context they used. The answers they give are very general, and if you want them to be based on your company's specific data, you'll need to retrain them using that data. However, if your data is constantly changing, continuously retraining the models can be computationally intensive and expensive. Additionally, by the time you finish retraining the model, your company may have already generated new data, making the model's information outdated.&lt;/p&gt;

&lt;p&gt;To address issues such as providing source links or offering more specific domain-related answers, Amazon Bedrock offers the "Knowledge Base" component. This feature provides additional data access during runtime. &lt;br&gt;
Using the Knowledge Base, you can create a RAG (Retrieval Augmented Generation) application that utilizes the "&lt;code&gt;RetrieveAndGenerate API&lt;/code&gt;" to fetch information from your Knowledge Base (KB) and generate responses. Alternatively, you can build a basic RAG Application with the "&lt;code&gt;Retrieve API&lt;/code&gt;", which retrieves information from the knowledge base and presents it to the user along with the source link.&lt;/p&gt;

&lt;p&gt;Beyond answering user queries, a KB can augment prompts for Foundational Models by adding context to the prompt. This adds RAG capability to Agents for Amazon Bedrock.&lt;/p&gt;

&lt;h4&gt;
  
  
  Agents For Bedrock
&lt;/h4&gt;

&lt;p&gt;The Amazon Bedrock Knowledge Base (KB) handles data ingestion, while agents manage the Retrieval Augmented Generation (RAG) workflow. Agents for Amazon Bedrock automates prompt engineering and the organization of user-requested tasks.&lt;/p&gt;

&lt;p&gt;Agents can perform various tasks, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Take actions to fulfill the users request.&lt;/p&gt;

&lt;p&gt;Agents have predefined Action groups, which are tasks they can autonomously perform. Each Action Group comprises some Lambda functions and API Schema. A crucial aspect of Schema Definition is the description of each Endpoint in your Schema. These descriptions can act as prompts to your Agent, helping it understand when to use which API Endpoint.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Break down complex user queries for Foundational Model.&lt;/p&gt;

&lt;p&gt;Agents assist Foundation Models in comprehending user requests. In the upcoming workflow explanations, I will delve deeper into how Agents employ ReAct strategies to analyse user requests and determine the actions that Foundation Models should take to fulfill those queries.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Collect additional information&lt;/p&gt;

&lt;p&gt;When you create an Agent for Amazon Bedrock, you can configure Agent to collect additional information from user through natural language conversation.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Common AI Workflows With Amazon Bedrock
&lt;/h3&gt;

&lt;p&gt;Having explored all the components of Amazon Bedrock, let's now delve into the most common patterns for integrating Amazon Bedrock into our Generative API applications. Knowing the common blueprints will help us to identify when a specific service is a good addition to our architecture and which blueprint is a good candidate for our use-case.&lt;/p&gt;

&lt;p&gt;Beginning with standard workflow to only use Amazon Bedrock API that invokes different models using "&lt;code&gt;InnvokeModel&lt;/code&gt;" API.&lt;br&gt;
This invocation can be initiated either by an event within you AWS account or through Application API.&lt;/p&gt;

&lt;p&gt;In an event driven workflow, the Model Invocation can occurs by S3 notifications when a file is uploaded to a specific S3 Bucket. This might be necessary when new files are uploaded to the bucket, and you want to summarise the document using Amazon Bedrock Foundational Models.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1aiaow05fzzc9fflycmj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1aiaow05fzzc9fflycmj.png" alt="event-driven" width="800" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You could also set up your Application API with an AWS Lambda Function that triggers a Foundational Model. For instance, it could generate text based on a user-provided topic or describe an image uploaded by the user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgbliadmy6onexyc877uj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgbliadmy6onexyc877uj.png" alt="generate-text" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This approach may appear simplistic, but that's the essence of utilising Amazon Bedrock as an API abstraction layer in your Generative AI application. Despite its simplicity, this method can yield effective responses and enhance answer quality using common techniques like Prompt engineering.&lt;/p&gt;

&lt;p&gt;The next pattern I'd like to discuss involves creating RAG applications using Knowledge Base, which blends prompt engineering techniques with retrieving information from external sources.&lt;/p&gt;

&lt;p&gt;To set up a RAG workflow, begin by creating a Knowledge Base in Amazon Bedrock. This involves specifying the S3 Bucket containing your external resources, determining the document chunk size, selecting the Embedding model to generate vectors for the dataset, and selecting a Vector Database to store the indexes, like Amazon OpenSearch. Setting the chunk size is crucial as it leads to finer embeddings, enhancing retrieval accuracy, and prevents overloading the model's context window with large source documents. &lt;/p&gt;

&lt;p&gt;Similar to most of AI powered workflows, this one also starts with user input prompt. RAG uses the same embedding model to create a vector embedding representation of the input prompt. This embedding is then used to query the Knowledge Base for similar vector embeddings to return the most relevant text as the query result. The query result is then added to the prompt, and the augmented prompt is passed to the FM. The model uses the additional context in the prompt to generate the response to the user query.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtwuf7hepqsit0ijy5x8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtwuf7hepqsit0ijy5x8.png" alt="RAG-Application" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like many AI-powered workflows, this one begins with a user input prompt. RAG uses an embedding model to create a vector representation of the input prompt. This vector is used to search the Knowledge Base for similar vectors, returning the most relevant text as the query result. The query result is then combined with the prompt and passed to the FM. The model uses the augmented prompt to generate a response to the user's query.&lt;/p&gt;

&lt;p&gt;Ever since I was young, I've saved the best for last. Let's talk about the Amazon Bedrock workflow with Agents. Here, you can surpass limitations by combining all Amazon Bedrock components, from the Knowledge Base to your company's APIs, to empower the Model to generate robust answers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo00qg5c5db5bh2d8ulot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo00qg5c5db5bh2d8ulot.png" alt="Agent-for-bedrock" width="800" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In an earlier section, I mentioned Agents extend FMs to understand user requests by breaking down complex tasks into multiple steps. This process occurs during the Pre-Processing phase. When an Agent receives a user request, it first analyses the request using ReAct Technique (Reason, Action, Observation).&lt;/p&gt;

&lt;p&gt;During this phase, the Agent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reasons on the user query to understand the task at hand, determining whether it needs to call an API or access a Knowledge Base for information.&lt;/li&gt;
&lt;li&gt;Takes action to fulfill the request by executing the necessary steps.&lt;/li&gt;
&lt;li&gt;Returns the observation or results after completing the actions. It then incorporates this information into the input prompt, providing the model with additional context (Augmented Prompt).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final Words
&lt;/h3&gt;

&lt;p&gt;Understanding the structure of Amazon Bedrock and the typical architectures for integrating it into Gen AI applications can help us make more informed decisions about which components to use to achieve our goals. However, it can be challenging to determine the best workflow, especially for those new to the Gen AI field.&lt;/p&gt;

&lt;p&gt;For simpler tasks that involve historical data, a standard approach with strong Prompt Engineering techniques is often effective. In contrast, for more complex tasks or when responses need to be specific to your dataset, leveraging Fine Tuning within Amazon Bedrock can be beneficial.&lt;/p&gt;

&lt;p&gt;When the model requires external data resources to fulfill user requests, using a Knowledge Base or a combination of a Knowledge Base and an Agent can be helpful. A Knowledge Base workflow is suitable for relatively static data such as company documents or FAQs, while an Agent with a Knowledge Base is better for dynamic information like databases or APIs.&lt;/p&gt;

&lt;p&gt;There is no one-size-fits-all solution, but the flexibility of Amazon Bedrock allows for various approaches to achieve the same result. The key is to choose the right approach for the task to achieve optimized results at minimal cost. &lt;/p&gt;

&lt;p&gt;I hope you found this article useful. In the next part, I will demonstrate the most advanced workflow, where we will use an Agent with APIs and a Knowledge Base to create a Tourist and Travel Assistant using Amazon Bedrock providing all the code snippets and code repository for your reference.&lt;/p&gt;

</description>
      <category>bedrock</category>
      <category>genai</category>
      <category>aws</category>
      <category>llm</category>
    </item>
    <item>
      <title>CDK Stack Notification Options</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Thu, 07 Mar 2024 09:18:45 +0000</pubDate>
      <link>https://forem.com/aws-builders/cdk-stack-notification-options-35f2</link>
      <guid>https://forem.com/aws-builders/cdk-stack-notification-options-35f2</guid>
      <description>&lt;p&gt;Today, I discovered yet again that there are countless ways to tackle a single task as a developer.&lt;/p&gt;

&lt;p&gt;I was tasked with automating a workflow that involved an AWS Lambda Function triggered by an SNS event source. The goal was to publish a message to an SNS topic in a different AWS account when the status of a CloudFormation stack updated.&lt;br&gt;
We use &lt;a href="https://docs.aws.amazon.com/cdk/v2/guide/home.html" rel="noopener noreferrer"&gt;AWS CDK&lt;/a&gt; for infrastructure as code (IAC). While exploring the documentation and blog posts, I found that there is no direct equivalent of the Notification Policy in CloudFormation to publish notifications to an SNS topic on a CloudFormation stack status change. Instead, there are several common patterns to achieve this. Let's start with solution diagram. Here's a simplified version of the architecture diagram of what I implemented:&lt;br&gt;
 If this is what you are looking for, you can simply achieve it in 3 different ways:&lt;/p&gt;
&lt;h2&gt;
  
  
  Using AWS Event Bridge
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create SNS Topic as a Stack B CDK resource:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Topic } from "aws-cdk-lib/aws-sns";

   const SNSTopic = new Topic(this, "SNS_TOPIC_ID", {
      displayName: "YOUR DISPLAY NAME",
    }); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;_Note: you need to add an event source to your function or any other resources that is going to subscribe to this topic. in my case I needed to configure a lambda event source as _bellow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MyFunction.addEventSource(new SnsEventSource(SNSTopic));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add Event Rule
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; new Rule(this, "Trigger", {
      eventPattern: {
        source: ["aws.cloudformation"],
        detailType: ["CloudFormation Stack Status Change"],
        detail: {
          eventName: ["CREATE_COMPLETE", "UPDATE_COMPLETE", "DELETE_COMPLETE"],
          requestParameters: {
            stackName: [this.stackName],
          },
        },
      },
      targets: [new SnsTopic(SNSTopic)],
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using AWS Custom Resources
&lt;/h2&gt;

&lt;p&gt;Second approach to achieve this is by using AWS Custom Resources.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an AWS Custom Resource within the Stack B CDK:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from "aws-cdk-lib/custom-resources";    

const Trigger = new AwsCustomResource(this, "TriggerOnSuccess", {
      onUpdate: {
        service: "SNS",
        action: "publish",
        parameters: {
          TopicArn: "YOUR_TOPIC_ARN",
          Message: "Stack updated successfully",
        },
        physicalResourceId: PhysicalResourceId.of("TriggerOnSuccess"),
      },
      onDelete: {
        service: "SNS",
        action: "publish",
        parameters: {
          TopicArn: "YOUR_TOPIC_ARN",
          Message: "Stack deleted successfully",
        },
        physicalResourceId: PhysicalResourceId.of("TriggerOnSuccess"),
      },
       policy: AwsCustomResourcePolicy.fromStatements( [new PolicyStatement({
        actions: ["sns:Publish"],
        effect: Effect.ALLOW,
        resources: [SNSTopic.topicArn],
      })]),
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add Dependency order so that CDK doesn't return Dependency Cycle error
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Trigger.node.addDependency(YOUR_FUNCTION);
 Trigger.node.addDependency(SNSS_TOPIC); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using AWS Custom Resource with Lambda Invoke Action
&lt;/h2&gt;

&lt;p&gt;There is also a 3rd solution for this as well which I am not a big fan of it and that is. I personally prefer to use fan out approach, to populate events to Lambda via an "Event Service" such as SNS or EventBridge. If you look for a simplified Custom Resource, here is what you should update your AWS Custom Resource to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from "aws-cdk-lib/custom-resources";    

const Trigger = new AwsCustomResource(this, "TriggerOnSuccess", {
      onUpdate: {
        service: "Lambda",
        action: "invoke",
        parameters: {
          FunctionName: "YOUR_FUNCTION_ARN",
          InvokationType: "Event"
        },
        physicalResourceId: PhysicalResourceId.of("TriggerOnSuccess"),
      },
      onDelete: {
        service: "Lambda",
        action: "invoke",
        parameters: {
          FunctionName: "YOUR_FUNCTION_ARN",
          InvokationType: "Event"
        },
        physicalResourceId: PhysicalResourceId.of("TriggerOnSuccess"),
      },
       policy: AwsCustomResourcePolicy.fromStatements( [new PolicyStatement({
        actions: ["lambda:InvokeFunction"],
        effect: Effect.ALLOW,
        resources: [YOUR_FUNCTION_ARN],
      })]),
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This concludes our brief discussion. While I'm still hopeful about discovering if CDK offers an API for configuring Stack Notification Options, I wanted to share these workarounds in the meantime.&lt;/p&gt;

</description>
      <category>cdk</category>
      <category>aws</category>
      <category>infrastructureascode</category>
    </item>
    <item>
      <title>Optimising Sentiment Analysis Workflows: AWS Zero-ETL and Amazon Redshift Synergy-Part 1</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Sun, 04 Feb 2024 05:01:39 +0000</pubDate>
      <link>https://forem.com/aws-builders/optimising-sentiment-analysis-workflows-aws-zero-etl-and-amazon-redshift-synergy-part-1-1c37</link>
      <guid>https://forem.com/aws-builders/optimising-sentiment-analysis-workflows-aws-zero-etl-and-amazon-redshift-synergy-part-1-1c37</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Being a passionate advocate for Machine Learning within Data Warehouses, I find the most intriguing aspect of this solution to be its ability to alleviate data fragmentation. By incorporating ML into your Data Warehouse, you centralize your data rather than dispersing fragments across various storage options such as Amazon S3 buckets or Azure Blob storage simply to enable accessibility for your machine learning tools. This represents just one of the numerous benefits that come with implementing ML in a Data Warehouse.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Warehouse Your New Data Lab!
&lt;/h2&gt;

&lt;p&gt;Today, leading cloud providers have made it super simple to venture into Machine Learning right from your Data Warehouse. Amazon Redshift boasts the Amazon Redshift ML feature, Azure Synapse Analytics buddies up with Azure ML, and Google BigQuery is your go-to for ML adventures. Even Snowflake is in on the action, offering SQL-based ML magic with SnowPark ML.&lt;/p&gt;

&lt;p&gt;At AWS:Reinvent, AWS made a big deal about Zero ETL Integration with Amazon Redshift and tossed in LLM models into Redshift ML. This seriously boosted the whole idea!&lt;/p&gt;

&lt;p&gt;In this blog post series, we'll explore the details of Zero ETL Integration with Amazon Redshift. Part one kicks off with connecting Amazon Aurora to Amazon Redshift, facilitating almost real-time data interactions in the Data Warehouse. Subsequently, in Part 2, we will harness this data for insightful analyses using advanced LLM models now accessible in Redshift ML.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simplify Data Movement With AWS Zero ETL Integration
&lt;/h2&gt;

&lt;p&gt;The ETL process (Extract, Transform, Load) is super important to prepare the data for a central Data Warehouse. This means Gathering, Cleaning, Normalising, and Combining data from different sources to make sure it's all set for use in the downstream system.&lt;/p&gt;

&lt;p&gt;Traditional ETL can be a bit of a hassle. It can cost a lot, be tricky to set up, and take a while to get the data ready.&lt;br&gt;
What if your primary goal is to provide your Data Analytics team with immediate access to the data? &lt;br&gt;
Zero-ETL integration is a fully managed solution. It has been designed to get your transactional or operational data into Amazon Redshift Data Warehouse almost in real time. As a fully managed solution it handles all the hard work on its own, making sure the data is secure and reducing the complexity of setting up the ETL Data Pipeline.&lt;/p&gt;
&lt;h3&gt;
  
  
  Aurora Zero ETL Integration With Amazon Redshift
&lt;/h3&gt;

&lt;p&gt;Aurora is designed more for online transactional processing rather than analytics. When handling extensive analytics queries, its performance can drop noticeably. A common practice is to have a primary database cluster and a read replica for analytics to improve performance.&lt;/p&gt;

&lt;p&gt;To tackle performance challenges, an advanced solution is also to set up an ETL data pipeline. You might opt for Amazon Data Migration Service (DMS) to move data to S3, utilise AWS Glue for ETL jobs, or employ Amazon EMR for distributed ETL and ML tasks. Afterwards, you can load the transformed data or model artifacts back to S3 and store the refined data in Redshift for analytics. With multiple steps involved, the concept of Zero ETL steps in, offering innovative solutions to simplify the process.&lt;/p&gt;
&lt;h3&gt;
  
  
  Set up Zero ETL Integration
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Considerations
&lt;/h4&gt;

&lt;p&gt;Before creating Zero ETL Integration in your Aurora database or any other databases that support this feature, it is essential to verify that the Aurora MySQL/PostgreSQL versions are compatible and indeed support Zero ETL Integration. To get the full list of prerequisites please check out &lt;a href="https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/zero-etl.troubleshooting.html#zero-etl.troubleshooting.creation" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To Set up Zero ETL Integration for your Aurora Source Database simply follow these steps:&lt;/p&gt;
&lt;h4&gt;
  
  
  Create a Custom DB Parameter Group
&lt;/h4&gt;

&lt;p&gt;First step to start with Aurora Zero ETL is to create a &lt;code&gt;Custom DB Parameter Group&lt;/code&gt; that controls replication and associate it with your Aurora DB cluster.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0sk8z0vzd8s108t6fq5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0sk8z0vzd8s108t6fq5.png" alt="create cluster parameter group" width="800" height="613"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhdt2zcitusq3rq4wblmj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhdt2zcitusq3rq4wblmj.png" alt="edit cluster parameters" width="800" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the cluster parameter group is created successfully, select the custom group and modify the values for each parameter as per bellow and hit save changes. In addition, Make sure &lt;code&gt;binlog_row_value_options&lt;/code&gt; parameter is unset.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  binlog_backup=0
  binlog_replication_globaldb=0
  binlog_format=ROW
  aurora_enhanced_binlog=1
  binlog_row_image=full
  binlog_row_metadata=full
  binlog_transaction_compression=OFF
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create Aurora Source Database
&lt;/h4&gt;

&lt;p&gt;If your Amazon Aurora DB Cluster are not already set up, the next step is to create Aurora Source Database instance. You can simply follow &lt;a href="https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.CreateInstance.html" rel="noopener noreferrer"&gt;the instruction&lt;/a&gt;. A few important notes to consider:&lt;/p&gt;

&lt;p&gt;1- To make sure the Aurora MySQL version set to 3.05.0 or higher.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpqxfkmpzcjlt7rqd6liw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpqxfkmpzcjlt7rqd6liw.png" alt="create source db cluster" width="800" height="776"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- Change the default DB cluster parameter group to the custom parameter group that you created in the previous step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1v4bu4hry7fsqxiy6pov.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1v4bu4hry7fsqxiy6pov.png" alt="modify source db cluster parameter group" width="800" height="688"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- To apply changes when associating the parameter group with the DB cluster after creating the cluster, you'll need to reboot the primary DB instance in the cluster before initiating a zero-ETL integration.&lt;/p&gt;

&lt;p&gt;For demonstration purposes I have downloaded a public dataset called &lt;code&gt;Consumer Reviews of Amazon Products&lt;/code&gt; from &lt;a href="https://www.kaggle.com/datasets/datafiniti/consumer-reviews-of-amazon-products" rel="noopener noreferrer"&gt;Kaggle&lt;/a&gt; and stored it into S3 Bucket. At the time of creating my Source DB Cluster I chose to restore data from S3. If you chose to restore data from S3 Bucket make sure you have given Aurora permissions to get objects from your S3 Bucket. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21fhadyxd08e7oaup6oc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21fhadyxd08e7oaup6oc.png" alt="add-data-to-cluster-from-s3" width="800" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8z478d72ksv8jamwbwwz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8z478d72ksv8jamwbwwz.png" alt="create-source-clister-in-progress" width="800" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Set up Redshift Serverless
&lt;/h4&gt;

&lt;p&gt;Next step is to set up &lt;a href="https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-console-workgroups-create-workgroup-wizard.html" rel="noopener noreferrer"&gt;Amazon Redshift Serverless Workgroup and NameSpace&lt;/a&gt; to use as our target data warehouse. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffotidiv9zr9ko2d873wr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffotidiv9zr9ko2d873wr.png" alt="redshift-serverless-successful-setup" width="800" height="201"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When Redshift NameSpace and WorkGroup are ready, for Zero ETL integration to be successful we must enable the &lt;code&gt;enable_case_sensitive_identifier&lt;/code&gt; parameter. To enable case sensitivity on a Redshift Serverless workgroup run this AWS CLI command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws redshift-serverless update-workgroup \
  --workgroup-name &amp;lt;YOU_REDSHIFT_SERVERLESS_WORKGROUP&amp;gt; \
  --config-parameters parameterKey=enable_case_sensitive_identifier,parameterValue=true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcozo1kqtiwlz1290e6z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcozo1kqtiwlz1290e6z.png" alt="enable-case-sensitive" width="731" height="683"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One last step before creating a Zero ETL integration is to add our Aurora Source DB as an authorised integration source to the namespace. This allows the Aurora Source DB to update our Amazon Redshift data warehouse. For that go to the Resource Policy tab and Add the ARN of the Aurora source DB as authorised integration source. We also need to add our AWS Account ID as authorised principal for Amazon Redshift.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpioyndht1ir0fm3v1rwu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpioyndht1ir0fm3v1rwu.png" alt="edit-integration-resource-policy" width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdxpmzubjwo14bpi2hx1s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdxpmzubjwo14bpi2hx1s.png" alt="update-integration-source-arn" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flte1jmvwdhwwu7j8wdbp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flte1jmvwdhwwu7j8wdbp.png" alt="edit-integration-principal-policy" width="800" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Create Zero ETL Integration
&lt;/h4&gt;

&lt;p&gt;To make this showcase easy to follow, I am using clicks up approach instead of &lt;a href="https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/zero-etl.setting-up.html#zero-etl.setup-sdk" rel="noopener noreferrer"&gt;setting up the integration using AWS SDK&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To create an Aurora zero-ETL integration with Amazon Redshift simply follow these steps: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuaey8dkankiop9v9gn2p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuaey8dkankiop9v9gn2p.png" alt="create-zero-etl-integration" width="800" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6pqwlxod1gohtfr1rtgf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6pqwlxod1gohtfr1rtgf.png" alt="create-zero-etl-1" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm0qb3ls5a2enls7zlkz9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm0qb3ls5a2enls7zlkz9.png" alt="create-zero-etl-2" width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Review the configuration and select create.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgapsdz570mvln6l3dr6j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgapsdz570mvln6l3dr6j.png" alt="create-zero-etl-3" width="800" height="628"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff6pud6r9a8jjjqzu8nhk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff6pud6r9a8jjjqzu8nhk.png" alt="create-zero-etl-4" width="800" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It takes approximately 30 minutes for the integration to be active. When the integration is successfully created, the status of the integration and the target Amazon Redshift data warehouse both change to Active.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnxbxxilw0xxbkg6o3f1x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnxbxxilw0xxbkg6o3f1x.png" alt="create-zero-etl-5" width="800" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Create Destination DataBase
&lt;/h4&gt;

&lt;p&gt;After successfully creating a zero-ETL integration, we must create a destination database within the target Amazon Redshift workgroup. I do it by using the query editor v2 by simply running the following SQL command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE DATABASE &amp;lt;DESTINATION_DB_NAME&amp;gt; FROM INTEGRATION '&amp;lt;INTEGRATION_ID&amp;gt;';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;To get the integration ID, navigate to the integration list on the Amazon Redshift console.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0kqbsgsvfwpklk2ke2v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0kqbsgsvfwpklk2ke2v.png" alt="create-zero-etl-data-base-redshift" width="800" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As simple as that! Now it's time to test the Zero-ETL integration in action.&lt;/p&gt;

&lt;h4&gt;
  
  
  How Zero ETL Works
&lt;/h4&gt;

&lt;p&gt;When Zero ETL integration is created, It first loads the existing data from source database to target Data Warehouse, then starts streaming transactional data into Amazon Redshift Destination Database.&lt;br&gt;
Let's test the Zero ETL Integration by adding Data to our Aurora MySQL Source DB.&lt;/p&gt;

&lt;p&gt;I use &lt;a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html#USER_ConnectToInstance.MySQLWorkbench" rel="noopener noreferrer"&gt;MySQL Workbench&lt;/a&gt; to connect to my Aurora instance and load new dataset into my table. As soon as new data is updated in the Aurora source database, we can query the destination table in Amazon Redshift and get the data back.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: If you have issues with connecting to your RDS instances I recommend to follow &lt;a href="https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.LoadFromS3.html" rel="noopener noreferrer"&gt;this page&lt;/a&gt; for troubleshooting. Also, If your RDS Clusters are inside a VPC make sure you have correct inbound policy attached to the security group.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhsh6aqnwx0040eqra7mm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhsh6aqnwx0040eqra7mm.png" alt="load_data_into_table" width="800" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F77wvgtm9ll98pkf4z29e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F77wvgtm9ll98pkf4z29e.png" alt="zero-etl-data-sync" width="800" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have the product feedback data available in Amazon Redshift, we can leverage pre-trained publicly available LLMs from Amazon Sagemaker JumpStart in Amazon Redshift ML to summarise feedback, perform entity extraction, sentiment analysis and product feedback classification.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Words
&lt;/h2&gt;

&lt;p&gt;To wrap it up I would like to review some advantages of employing Zero ETL integration include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data is seamlessly available in Redshift.&lt;/li&gt;
&lt;li&gt;Enables us to run near real time analytics, visualisation and ML on the data without impacting the production workloads.&lt;/li&gt;
&lt;li&gt;With Zero ETL we don’t need to build and maintain complex Data pipelines to perform ETL operations. Still there are lost of other use cases to create and maintain a data pipeline but if it is specifically to run analytics processing, it’s convenient to use zero ETL integration.&lt;/li&gt;
&lt;li&gt;Zero ETL with Redshift is provided at no additional cost.&lt;/li&gt;
&lt;li&gt;We can create integration from multiple source Databases into a single Redshift warehouse.&lt;/li&gt;
&lt;li&gt;We can have end to end serverless solution with Aurora serverless and Redshift serverless.&lt;/li&gt;
&lt;li&gt;There is consistent monitoring on Zero ETL Integration, it detects when data tables need to be reseeded. When integration need to be Fixed or Recovered, and it’s healed automatically.&lt;/li&gt;
&lt;li&gt;Also Redshift sends integration related events to Amazon EventBridge.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Zero ETL is a one step easy and secure way to enable near real time analytics on transactional or operational Data. Also, The new &lt;a href="https://docs.aws.amazon.com/redshift/latest/dg/r_SUPER_type.html" rel="noopener noreferrer"&gt;Super&lt;/a&gt; data type has advanced the Amazon Redshift ML capabilities, allowing integration of large language models (LLM) from SageMaker JumpStart for remote inferences. Combining these two features will empower us to create an end to end robust ML/AI solution faster but cost effectively.&lt;br&gt;
Keep an eye out for Part 2, where we leverage an LLM Model in Redshift for immediate sentiment analysis on our dataset.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>zeroetl</category>
      <category>redshift</category>
      <category>sagemaker</category>
    </item>
    <item>
      <title>Do you believe AI will replace your job?</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Thu, 14 Dec 2023 05:55:45 +0000</pubDate>
      <link>https://forem.com/aws-builders/do-you-believe-ai-will-replace-your-job-5c00</link>
      <guid>https://forem.com/aws-builders/do-you-believe-ai-will-replace-your-job-5c00</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;A few weeks ago, I chatted with a lady at the bus station. We both work in tech and share an interest in it. When we talked about our passion for technology, she asked, "Do you think AI will replace your job?". This question often arises in discussions about AI and ML. In my view, AI and ML won't replace us; they'll boost our abilities, making medical diagnoses more accurate, strengthening security, and improving overall work efficiency.&lt;/p&gt;

&lt;p&gt;Am I worried about AI taking over my job after &lt;code&gt;AWS Re:Invent&lt;/code&gt; last week, where they introduced services like &lt;a href="https://aws.amazon.com/q/" rel="noopener noreferrer"&gt;Amazon Q&lt;/a&gt; and &lt;a href="https://aws.amazon.com/codecatalyst/" rel="noopener noreferrer"&gt;Amazon CodeCatalyst&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;Should I be concerned about my job as a Developer with these AI services? Let's explore together and learn more about them.&lt;/p&gt;

&lt;p&gt;You probably know SST Framework and Svelte Kit – nothing groundbreaking. Despite not being an expert in Svelte and SST recently, I decided to experiment with these tools, combining SST and Svelte with Amazon Q and Amazon CodeWhisperer using the AWS Toolkit in the IDE.&lt;/p&gt;

&lt;p&gt;In this blog post, I'll share my thoughts on this setup and how I found these services through the Amazon Toolkit. You'll also find out if we should be concerned about AI assistants taking over our jobs as Developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  An Introduction to Svelte, SST, Amazon Q and Amazon CodeWhisperer
&lt;/h2&gt;

&lt;p&gt;Before diving into writing code and utilising various services from the Amazon Toolkit in VSCode, it's worth taking a quick look at what we're about to use, especially if you're not familiar with them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Svelte
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://svelte.dev/" rel="noopener noreferrer"&gt;Svelte&lt;/a&gt; is a JavaScript tool for constructing UI components, similar to other UI frameworks like React and Vue. However, what sets Svelte apart is that it functions as a compiler, transforming the code into a form compatible with native browser APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  SST Framework
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://sst.dev/" rel="noopener noreferrer"&gt;SST&lt;/a&gt; is an open-source framework designed to facilitate the development and deployment of Serverless stacks on AWS. It operates under the hood by integrating with Amazon CDK. However, its primary benefit is in allowing us to concentrate on creating resources using familiar languages like TypeScript, treating them as Infrastructure as Code (IaC).&lt;/p&gt;

&lt;h3&gt;
  
  
  Amazon Q
&lt;/h3&gt;

&lt;p&gt;Imagine OpenAI's ChatGPT, Microsoft's Copilots, and now, Amazon has introduced its own AI assistant called &lt;a href="https://aws.amazon.com/q/" rel="noopener noreferrer"&gt;Amazon Q&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are different ways we can use Amazon Q. You can connect it to your business data for a personalised touch to suit your specific nee&lt;br&gt;
ds like a chatbot that is customised for your business.&lt;/p&gt;

&lt;p&gt;It's also accessible within the AWS console as an expert who can give you suggestions on architecture and solution designs with best practices. Amazon Q seamlessly integrates with Amazon Insight. This integration assists with visualisations, data analysis, and answering any data-related questions you may have. More importantly, as a developer, you can leverage Amazon Q within your IDE for code improvements, debugging and troubleshooting. That's the use case I am going to focus on in this blog.&lt;/p&gt;

&lt;h3&gt;
  
  
  Amazon CodeWhisperer
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://aws.amazon.com/codewhisperer/" rel="noopener noreferrer"&gt;CodeWhisperer&lt;/a&gt; is a GenAI-powered tool that assists with code recommendations based on Pseudocode or existing codes. It can be configured within your IDE or through the command line. Extending its capabilities, CodeWhisperer is compatible with certain AWS services, including &lt;a href="https://docs.aws.amazon.com/codewhisperer/latest/userguide/sagemaker-setup.html" rel="noopener noreferrer"&gt;Amazon SageMaker Studio&lt;/a&gt; and &lt;a href="https://docs.aws.amazon.com/codewhisperer/latest/userguide/glue-setup.html" rel="noopener noreferrer"&gt;Amazon Glue Studio&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can utilise Amazon CodeWhisperer at no cost by &lt;a href="https://aws.amazon.com/codewhisperer/resources/#Getting_started/" rel="noopener noreferrer"&gt;configuring it within your IDE&lt;/a&gt;, Authenticate and you're ready to start leveraging its features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Experimenting with Amazon Q and Amazon CodeWhisperer
&lt;/h2&gt;

&lt;p&gt;I built a full-stack application using React, NextJs, and AWS Serverless. Check out the &lt;a href="https://dev.to/aws-builders/story-telling-app-with-amazon-bedrock-1259"&gt;blog post&lt;/a&gt; for a guide on incorporating ML features with Amazon Bedrock into your application. In this part, I'll explain how I used Amazon Q and CodeWhisperer to rebuild the story generator lambda function in my app. Since I wasn't familiar with the SST framework and Svelte initially, I did some reading and &lt;a href="https://www.youtube.com/watch?v=E547i_xPqrU" rel="noopener noreferrer"&gt;watched tutorials&lt;/a&gt; before using Amazon Q to assess responses or CodeWhisperer's code recommendations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Amazon Q For Analysing And Explanation
&lt;/h2&gt;

&lt;p&gt;I began by asking Amazon Q about the SST framework, hoping for a quick and helpful response.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkxab29qvywkmf73pi1z2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkxab29qvywkmf73pi1z2.png" alt="what-is-sst-answer" width="777" height="805"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, I am keen to know how SST integrates with Svelte.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvldozin0ctp83a15zpql.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvldozin0ctp83a15zpql.png" alt="how-to-integrate-sst-with-svelte" width="800" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This convinces me. Now, let's find out how to get started with Svelte. I asked Amazon Q for guidance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9nf54ix7h9ao9moctogq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9nf54ix7h9ao9moctogq.png" alt="create-svelte-app" width="557" height="624"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I ran the suggested command, and the Svelte app was created successfully. Then, I asked Amazon Q to explain the structure of a Svelte project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqk0ec496sgq2yjm0n4sw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqk0ec496sgq2yjm0n4sw.png" alt="cli-command" width="800" height="50"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyba6zfcriwg8vambeo4s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyba6zfcriwg8vambeo4s.png" alt="svelte-app" width="565" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftyossgm06cnn6u7qae74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftyossgm06cnn6u7qae74.png" alt="svelte-explanations" width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before diving into this experiment, I studied the concept of using SST as a Serverless stack with a UI framework like Svelte. The key idea is to have a mono repo, a recommended structure that makes all resources accessible to the Frontend.&lt;/p&gt;

&lt;p&gt;Understanding these fundamental concepts, even with an AI assistant, helps in asking accurate questions and receiving precise answers. This approach prevents blindly accepting the assistant's recommendations.&lt;/p&gt;

&lt;p&gt;Next, I'll use Amazon Q to inquire about creating an SST Stack and initialising a Svelte app within an SST app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc6cby2f0vzgea57b2alc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc6cby2f0vzgea57b2alc.png" alt="create-sst-app" width="800" height="630"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I like how Amazon Q gives a source link for each part of the answer and suggests follow-up questions as you can see in the screenshots. In this case, I found the SST app creation command in the source. After a few minutes, the SST app was successfully created. To follow best practices, I'll move the Svelte app to the my-sst-app/packages folder, turning the project into a mono repository. Alternatively, you can create a new Svelte app within the SST App.&lt;/p&gt;

&lt;h2&gt;
  
  
  Amazon Q &amp;amp; CodeWhisperer For Coding
&lt;/h2&gt;

&lt;p&gt;Now, with our SST and Svelte apps set up, let's try out Amazon CodeWhisperer and request an explanation of the code from Amazon Q. We'll use Amazon CodeWhisperer to write the initial lambda function to generate a story with Amazon Bedrock.&lt;/p&gt;

&lt;p&gt;Here's the pseudo-code for the lambda function:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiulu35qbggnvlm0k327w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiulu35qbggnvlm0k327w.png" alt="pseudo-coded-lambda" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When using Amazon CodeWhisperer, wait for suggestions based on your pseudo code, then choose the most relevant one. Alternatively, start typing, and it will provide recommendations. Proceed line by line to complete the lambda function, and I will analyse the suggestions once the lambda implementation is finished.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To bring in the bedrock client in my SST App, I referred to Amazon Q for guidance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk235ulkfzz38m77267um.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk235ulkfzz38m77267um.png" alt="how-import-bedrock-client" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extract and validate the topic from the lambda event&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffqu91f9ciwz7tuk3jf8x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffqu91f9ciwz7tuk3jf8x.png" alt="extract-topic" width="800" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fra7u3w8v2v5puoqkl7zb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fra7u3w8v2v5puoqkl7zb.png" alt="validate-topic" width="753" height="712"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Construct Prompt&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftd7mg6zg0lws0y8n0k0j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftd7mg6zg0lws0y8n0k0j.png" alt="propmpt" width="800" height="603"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Construct Payload&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21sf1il0gsnyptstkuic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21sf1il0gsnyptstkuic.png" alt="construct payload" width="800" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initialise Bedrock Client and invoke the model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fii48o0rsyzb8iyhi3ken.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fii48o0rsyzb8iyhi3ken.png" alt="bedrock-client" width="762" height="705"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88np1198cix044obanks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88np1198cix044obanks.png" alt="invoke command" width="785" height="635"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Amazon Q For Debugging
&lt;/h2&gt;

&lt;p&gt;Close to completing the lambda implementation. After applying the suggested code for model invocation, I had to import InvokeModelCommand from Amazon Bedrock. Let's ask Amazon Q about importing the module.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwvsfy65duqj9ssfb6gwd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwvsfy65duqj9ssfb6gwd.png" alt="invoke model" width="800" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I follow the suggestions, I'll encounter an import resolution error. Now, I'm using Amazon Q for debugging.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fza6vrqbkhxy70b7y0i97.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fza6vrqbkhxy70b7y0i97.png" alt="error" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fleb6mu98zyoxh38067p7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fleb6mu98zyoxh38067p7.png" alt="amazon q debugging" width="733" height="566"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I've used the Amazon Bedrock SDK before, and I know that &lt;code&gt;InvokeModelCommand&lt;/code&gt; is in the &lt;a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/" rel="noopener noreferrer"&gt;client-bedrock-runtime &lt;/a&gt;package. Despite tweaking my question for specificity, the response continued to reference the &lt;code&gt;client-bedrock&lt;/code&gt; package. Just to be thorough, I asked the same question to ChatGPT and received a similar response.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbh5eexacqg11arodrjpw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbh5eexacqg11arodrjpw.png" alt="chatgpt debugging" width="800" height="1002"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The answer seems a bit misleading. As I followed the AI assistant's suggestions for implementing the lambda function, more errors occurred. For example, I had to import the Bedrock Client from &lt;code&gt;client-bedrock-runtime&lt;/code&gt;, and the suggested payload was incorrect. The AI couldn't guide me on how to destructure the generated text response from the Text Model. After fixing these issues, the lambda function for generating the story is now implemented properly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwuziiwudvj4usaq4g9i4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwuziiwudvj4usaq4g9i4.png" alt="implemented lambda" width="750" height="855"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So far, I used Amazon Q and CodeWhisperer for various tasks like general knowledge questions, coding, and debugging. This experiment continued, I explored using Amazon Q to integrate an AppSync API resource into an SST Stack, deploying the stack, and creating a simple form with a single input field in Svelte. To keep this post concise, I'll conclude my documentation of this experiment here. In the next part, I'll share my thoughts on how the experiment went.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Did This Experiment Go?
&lt;/h2&gt;

&lt;p&gt;My experiment with Amazon Q and CodeWhisperer wasn't limited to a lambda function; I used CodeWhisperer in Amazon Glue Studio and found it efficient.&lt;/p&gt;

&lt;p&gt;Will I use or recommend Amazon Q? Absolutely. Setting it up in my VSCode is convenient, and it's not just for coding – Amazon Q works magic for data analytics and architecture solutions. Check out &lt;a href="https://dev.to/aws-heroes/amazon-q-in-amazon-quicksight-previewpart-1-build-dashboards-with-nlp-339o"&gt;Wendy's blog post&lt;/a&gt;, an AWS Data Hero, explaining how Amazon Q integrates with Amazon Insights and unleashes its power. The provided source link is also helpful.&lt;/p&gt;

&lt;p&gt;Are AI answers convincing? I'd say they're quite good. They work well not just for coding and debugging; if you provide an Infrastructure as Code (IaC) template, the AI can analyze it and suggest AWS best practices. When using AI assistants like ChatGPT or Amazon Q, the key is the user's input or "Prompt."&lt;/p&gt;

&lt;p&gt;The assistant answers and recommends based on your input. For instance, when a lambda implementation error occurred, I used Amazon CodeWhisperer to import the Bedrock Client package. This time, modified the pseudo code from &lt;code&gt;import Bedrock Client&lt;/code&gt; to &lt;code&gt;import Bedrock runtime client&lt;/code&gt;, and it correctly imported the modules. Pseudo-code precision matters and CodeWhisperer also recommends based on existing code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftr2qbgguwauzn51exi4w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftr2qbgguwauzn51exi4w.png" alt="bedrock-runtime-client" width="729" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Will I use AI assistants for learning and software development?&lt;/p&gt;

&lt;p&gt;It depends on whether they're designed for training and learning purposes. Otherwise, following their suggestions might be confusing. They're meant to assist, not do the job for you. I tested Amazon Q and Amazon CodeWhisperer for error fixing and code optimisation, and they performed well. While expecting AI bots like ChatGPT, Amazon Q, or Microsoft Copilot to build your app may be premature, Amazon Q provides solid AWS best practices recommendations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhs5zblezssumxhwheoj9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhs5zblezssumxhwheoj9.png" alt="analyse IaC" width="800" height="763"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0jkmz4w521y8t6814s1c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0jkmz4w521y8t6814s1c.png" alt="best practices" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Should we worry about AI taking over our jobs?&lt;br&gt;
I believe that AI/ML is here to assist and improve our lives. AI extends beyond the technology, impacting various domains with daily use cases. However, will it replace our roles soon? I remain optimistic and say no. We build and train AI solutions, teaching them to save time, cost, and lives. the intention is not to replace roles but practicing responsible use of AI can lead to a brighter future.&lt;/p&gt;

&lt;p&gt;In closing, I want to share one of my favourite paragraphs from Chip Huyen's book "Designing Machine Learning Systems." All credit to the author.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In early 2020, the Turning Award winner Professor Geoffrey Hinton proposed a heatedly debated question about the importance of interpretability in ML systems. Suppose you have cancer and you have to choose between a black box AI surgeon who can not explain how it works but has a 90% cure rate and a human surgeon with an 80% cure rate. Do you want the AI surgeon to be illegal? A couple of weeks later, when I asked this question to a group of 30 technology executives at public nontech companies, only half of them would want the highly effective but unable-to-explain AI surgeon to operate on them. The other half wanted the human surgeon. While most of us are comfortable with using a microwave without understanding how it works, many don't feel the same way about AI yet, especially if that AI makes important decisions about their lives.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>amazonq</category>
      <category>amazoncodewhisperer</category>
      <category>aws</category>
      <category>genai</category>
    </item>
    <item>
      <title>Musical Concierge on AWS</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Mon, 04 Dec 2023 11:01:42 +0000</pubDate>
      <link>https://forem.com/aws-builders/musical-concierge-on-aws-1nfm</link>
      <guid>https://forem.com/aws-builders/musical-concierge-on-aws-1nfm</guid>
      <description>&lt;h2&gt;
  
  
  Initial Words
&lt;/h2&gt;

&lt;p&gt;In the world of GenAI applications, we often overlook the amazing tools provided by cloud service providers like AWS to explore Machine Learning.&lt;/p&gt;

&lt;p&gt;AWS, in particular, offers a comprehensive set of services, covering Data Analytics and Real-Time Data Streaming. When you combine these with AI and ML services like Amazon Rekognition, you can tap into Machine Learning without the complexity of setting up infrastructure or the costs and time required to train models from scratch.&lt;/p&gt;

&lt;p&gt;To learn and understand these services, the best approach is to get hands-on. I usually start by thinking about real-world scenarios, explore existing solutions, and then build my idea using the tech and tools I'm comfortable with.&lt;/p&gt;

&lt;p&gt;With the new year approaching, I wanted to welcome my guests uniquely. I remembered my security camera was getting dust in my storage. What if I could use it to capture my visitors' arrival and integrate it with a system that not only informs me when they arrive but also recommends a custom song for each visitor to keep them entertained while I get ready to welcome them to the party?&lt;/p&gt;

&lt;p&gt;Great! We now have the idea, let's call it "Musical Concierge".&lt;/p&gt;

&lt;h2&gt;
  
  
  Mixing The Right Ingredients On AWS For A Musical Concierge
&lt;/h2&gt;

&lt;p&gt;AWS Resources and Hardware to build your Musical Concierge: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2xwy0td0bltbu4y83ie.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2xwy0td0bltbu4y83ie.png" alt="required services for musical concierge" width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Guided Tour Of Architecture Diagram
&lt;/h2&gt;

&lt;p&gt;Understanding the essential cake ingredients is just the beginning; it's the art of blending them that gives each cake its unique flavour. Similarly, now that we have the ingredients for crafting our Concierge tool, let's dive into the designed architecture and follow the instructions to bring it to life.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fde95hnxzby5rcu12u9cv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fde95hnxzby5rcu12u9cv.png" alt="Architecture diagram" width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our tech setup, the main thing we need is an IP camera for the video source. There are many ways to do this project, but I went with what I have—a Tapo C310 IP camera because it supports RTSP (Real-Time Streaming Protocol). RTSP is important for smoothly streaming the captured video from the camera into a service like Amazon Kinesis Video Streams.&lt;/p&gt;

&lt;p&gt;To playback the camera's video stream, we can use Amazon Kinesis Video Streams. This service works with Amazon Rekognition for computer vision and video analytics. So, when the video streams reach our AWS account, Amazon Rekognition can recognise familiar faces.&lt;/p&gt;

&lt;p&gt;If you're wondering how Amazon Rekognition does this, it uses something called a "face collection". We can make different face collections and add faces to them. When the video stream data goes to Amazon Rekognition, it looks at the face collection and identifies faces based on the ones we added.&lt;/p&gt;

&lt;p&gt;When it finds a match, Amazon Rekognition sends out the results. But we're not done yet—we need another way to deliver these results smoothly to a place like an AWS Lambda function. For this, we can use Amazon Kinesis Data Streams as a delivery service.&lt;/p&gt;

&lt;p&gt;Now, you can get creative and use the analysis results however you want. But for our case, we need a Lambda function that sends the face recognition result to Amazon SNS (Simple Notification Service) as a messaging service. Amazon SNS lets us send the results to different subscribers, like a Lambda function that notifies us through SMS or apps like Telegram when our visitors arrive. We can even have a Lambda function subscribed to the same SNS topic that recommends a custom song for each visitor based on the music they like.&lt;/p&gt;

&lt;p&gt;Now that we have a general idea of how the application works, it's time to set up the hardware and AWS resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure Resources
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Camera
&lt;/h3&gt;

&lt;p&gt;To set up the camera, first, you need to find its IP address. To do this, log in to your network router and look for the IP address of your device.&lt;/p&gt;

&lt;h4&gt;
  
  
  Create Camera Account
&lt;/h4&gt;

&lt;p&gt;No matter what IP camera you have, it usually comes with a mobile app that lets you control the camera. For my 'Tapo C310' camera, I used the TP-Link App and made a camera account. This account info is needed by Amazon Kinesis Video Streams' Client to make sure it's authorised to get the video from the camera.&lt;/p&gt;

&lt;p&gt;This camera account is separate from your TP-Link App login. If you don't give these details, Kinesis Video Streams won't be able to get the video from the camera. If you're using the same camera as me, you can &lt;a href="https://www.tp-link.com/us/support/faq/2790/" rel="noopener noreferrer"&gt;check out the instructions here&lt;/a&gt; on how to create your camera account.&lt;/p&gt;

&lt;p&gt;Now, your camera is all set to send the video to the cloud. The next step is getting things ready in the cloud.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create AWS Resources With CloudFormation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqtjah0ft9o86s06w6ojq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqtjah0ft9o86s06w6ojq.png" alt="aws cloudformation" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we know what services we need from the list, we can easily set them up in AWS. I'll use CloudFormation to create these resources in our AWS account.&lt;/p&gt;

&lt;h4&gt;
  
  
  Amazon Kinesis Resources
&lt;/h4&gt;

&lt;p&gt;Let's start with Amazon Kinesis Family:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  # Amazon Data Stream
  MusicalConciergeDataStream:
    Type: "AWS::Kinesis::Stream"
    Properties: 
      Name: !Sub ${ApplicationName}-Data-Stream
      ShardCount: 1
  # Amazon Video Stream
  MusicalConciergeVideoStream:
    Type: AWS::KinesisVideo::Stream
    Properties:
      DataRetentionInHours: 24
      Name: !Sub ${ApplicationName}-Video-Stream

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that Amazon Kinesis Video Streams (KVS) availability is limited in certain regions. To optimize performance and ensure support for the KVS service, it's essential to deploy the stack in a region that is both geographically close to you and a supported region for KVS.&lt;/p&gt;

&lt;h4&gt;
  
  
  Amazon Rekognition Resources
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Rekognition Stream Processor
&lt;/h5&gt;

&lt;p&gt;Now that our camera's live video is flowing into Kinesis Video Streams in real-time, you might be curious about how it recognises your visitors and what services make it happen. Well, as I mentioned earlier the answer is simple: we just use "Amazon Rekognition Stream Producer" and a "Face Collection".&lt;/p&gt;

&lt;p&gt;When the live video data gets to Amazon Rekognition, it looks through a collection of images from different people.&lt;/p&gt;

&lt;p&gt;You can set up the face collection and Rekognition Stream Producer using this CloudFormation snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  RekognitionFaceCollection:
    Type: AWS::Rekognition::Collection
    Properties:
      CollectionId: !Ref MusicalConciergeFaceCollectionId

  RekognitionStreamProcessor:
    Type: AWS::Rekognition::StreamProcessor
    Properties:
      Name: "MusicalConciergeStreamProcessor"
      RoleArn: !GetAtt RekognitionVideoIAMRole.Arn
      KinesisVideoStream: 
        Arn: !GetAtt MusicalConciergeVideoStream.Arn
      FaceSearchSettings:
        CollectionId: !Ref MusicalConciergeFaceCollectionId
        FaceMatchThreshold: 98
      KinesisDataStream: 
        Arn: !GetAtt MusicalConciergeDataStream.Arn

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Rekognition Iam Role
&lt;/h5&gt;

&lt;p&gt;We need an IAM role for Amazon Rekognition service that allows Rekognition to get the Video Data stream from Amazon Kinesis Video Streams service and put the Facial Match Records into Amazon Kinesis Data Stream, for that we need a policy like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  RekognitionVideoIAMRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          -
            Effect: Allow
            Principal:
              Service: rekognition.amazonaws.com
            Action: sts:AssumeRole
      Path: '/'
      Policies:
        -
          PolicyName: RekognitionVideoIAMRole-policy
          PolicyDocument:
            Version: '2012-10-17'
            Statement:
              -
                Effect: Allow
                Action:
                    - 'kinesis:PutRecord'
                    - 'kinesis:PutRecords'
                Resource: !GetAtt MusicalConciergeDataStream.Arn
              -
                Effect: Allow
                Action:
                    - 'kinesisvideo:GetDataEndpoint'
                    - 'kinesisvideo:GetMedia'
                Resource: !GetAtt MusicalConciergeVideoStream.Arn
              -
                Effect: Allow
                Action:
                    - 'rekognition:*'
                Resource: '*'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create Joy From Amazon Rekognition Analysis
&lt;/h3&gt;

&lt;p&gt;Once the AWS Lambda gets the matching face analysis from Amazon Kinesis Data Streams, we can do lots of cool things with it. We can use it however we want—like sending a text to tell us our visitor is here with their name, or playing a nice song for them as they wait for our welcoming hello at the door.&lt;/p&gt;

&lt;p&gt;To make our two Lambda functions—one for publishing a message to Amazon SNS topic containing the face recognition result and the other for suggesting music—we can use the cloudformation resources like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  GetVideoAnalysisLambda: 
    Type: "AWS::Lambda::Function"
    Properties: 
      Code: ./.build/GetVideoAnalysis.zip
      FunctionName: GetVideoAnalysisLambda
      Handler: src/GetVideoAnalysis.handler
      Role: !GetAtt GetVideoAnalysisLambdaRole.Arn
      Environment:
        Variables:
          SNS_TOPIC: !Ref SNSTopic
      Runtime: "nodejs18.x"
      MemorySize: 1024
      Timeout: "900"

  GetVideoAnalysisLambdaKinesisMapping:
    Type: "AWS::Lambda::EventSourceMapping"
    Properties: 
      BatchSize: 10
      Enabled: true
      EventSourceArn: !GetAtt MusicalConciergeDataStream.Arn
      FunctionName: !GetAtt  GetVideoAnalysisLambda.Arn
      StartingPosition: "TRIM_HORIZON"

  InformHostLambda: 
    Type: "AWS::Lambda::Function"
    Properties: 
      Code: .build/InformHost.zip
      FunctionName: InformHostLambda
      Handler: src/InformHost.handler
      Role: !GetAtt InformHostLambdaRole.Arn
      Environment:
        Variables:
          BUCKET_NAME: !Ref ConciergeAudioBucketName
          SECRET_NAME: !Ref TelegramBotSecretName
      Runtime: "nodejs18.x"
      MemorySize: 1024
      Timeout: "900"

  InformHostLambdaPermission:
    Type: AWS::Lambda::Permission
    Properties:
      Action: lambda:InvokeFunction
      FunctionName: !GetAtt InformHostLambda.Arn
      Principal: sns.amazonaws.com
      SourceArn: !Ref SNSTopic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to know what each lambda function does, check out the examples in this code repository on &lt;a href="https://github.com/RonakReyhani/MusicalJoyBells/blob/main/src/Implementation/MusicalJoyStore.ts" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. You can use them as a starting point and change them however you like.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deploy Resources as Infrastructure as Code
&lt;/h3&gt;

&lt;p&gt;We are nearly there, through cloudformation snippets from this blog post we almost created all the core resources required for the Musical Concierge. However, there are some other resources such as Amazon Secrets Manager or AWS S3 Buckets to store the face images or collection of musics, to access the full version of all the resources please check out the cloudformation file in &lt;a href="https://github.com/RonakReyhani/MusicalJoyBells/blob/main/cloudformation.yaml" rel="noopener noreferrer"&gt;this code repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Time to deploy all the resources in AWS account. Go ahead and continue with build, package and deploying the resources.&lt;/p&gt;

&lt;h4&gt;
  
  
  Build and Package
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run build
npm run package

aws cloudformation package --template-file ./cloudformation.yaml --s3-bucket $ARTIFACT_BUCKET --output-template-file /&amp;lt;FOLDER&amp;gt;/cloudformation.yaml

aws cloudformation deploy \
  --template /path_to_template/my-template.yml \
  --stack-name &amp;lt;STACK_NAME&amp;gt; \
  --parameter-overrides Key1=Value1 Key2=Value2 \
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;In this project I have not set up CI/CD, if you are planing to productionise this project, make sure this step is part of your continues integration and continues deployment.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After successful deployment of cloudformation resources, it's time to link everything together and make the videos flow into Amazon resources. We'll do that in the next few steps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure Face collection (AWS CLI)
&lt;/h3&gt;

&lt;p&gt;To make Amazon Rekognition recognize faces in the live stream, we have to give it a collection of known faces. In earlier steps, we made this collection. Now, to add familiar faces to it, you can use AWS CLI. This part requires some manual work, though. You must have set up your AWS CLI and put in your credentials to run these commands and make it work.&lt;/p&gt;

&lt;h4&gt;
  
  
  Add images to the face collection:
&lt;/h4&gt;

&lt;p&gt;I put some photos of faces in a folder on S3. When I run this command, it grabs the photo from S3 and adds it as a new face to my collection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  aws rekognition index-faces \
    --image '{"S3Object":{"Bucket":"&amp;lt;BUCKET_NAME&amp;gt;","Name":"&amp;lt;FILE_NAME&amp;gt;.jpg"}}' \
    --collection-id "&amp;lt;COLLECTION_ID&amp;gt;" \
    --detection-attributes "ALL" \
    --external-image-id "&amp;lt;FACE-TAG&amp;gt;" \
    --region &amp;lt;AWS_REGION&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Tip: make sure the region of your bucket is same as face collection&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Start Rekognition Stream Producer (AWS CLI)
&lt;/h3&gt;

&lt;p&gt;Rekognition Stream Producer is the heart of the system. It pulls video from Kinesis video, analyzes it &amp;amp; pushes the results to Kinesis data. Earlier, We created the Amazon Rekognition Procession within the cloudformation lets get a list of existing processors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To List Rekognition Stream Producer run this command in your terminal:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws rekognition list-stream-processors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the Rekognition Stream Producer is initially created, the default status is "STOPPED":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output:
{
    "StreamProcessors": [
        {
            "Name": "musical-concierge-rekognition-processor",
            "Status": "STOPPED"
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To Start Rekognition Stream Producer run this command in your terminal:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws rekognition start-stream-processor \
    --name &amp;lt;PROCESSOR_NAME&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After starting the Stream Producer the status will change to "Running":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "StreamProcessors": [
        {
            "Name": "musical-concierge-rekognition-processor",
            "Status": "RUNNING"
        }
    ]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Connect the Camera as a stream source (Producer) for Kinesis Video Stream
&lt;/h4&gt;

&lt;p&gt;After setting up Amazon Kinesis, it's time to send data to it. We can use the SDK to create code for our application. This code grabs video data, called frames, from the video source and sends it to Kinesis Video Streams. These apps are also called producers.&lt;/p&gt;

&lt;p&gt;The producer libraries usually have two parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kinesis Video Streams Producer Client&lt;/li&gt;
&lt;li&gt;Kinesis Video Streams Producer Library&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Kinesis Video Streams doesn't have ready-made setups for devices like cameras. To get data from media devices, you need to write code to create your own custom media source. After that, you can register your custom media sources with 'KinesisVideoClient', and it will send the data to Kinesis Video Streams.&lt;/p&gt;

&lt;p&gt;To implement the application to extract and upload the data to Kinesis Video stream from scratch I recommend to follow &lt;a href="https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/producer-sdk-javaapi.html" rel="noopener noreferrer"&gt;this document page on AWS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That might seem to be very complex but thanks to Docker we can build the entire application as a Docker image and use one of the provided samples from &lt;a href="https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp/blob/master/samples/kvs_gstreamer_sample.cpp" rel="noopener noreferrer"&gt;AWS Amazon Kinesis Repository&lt;/a&gt; to start with uploading the data to Kinesis.&lt;/p&gt;

&lt;p&gt;For Musical Concierge app I have used the docker image approach:&lt;/p&gt;

&lt;p&gt;1- Set up docker if it's first time using Docker &lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;get Docker&lt;/a&gt;.&lt;br&gt;
2- Copy provided Docker File &lt;a href="https://github.com/RonakReyhani/MusicalJoyBells/blob/main/Dockerfile" rel="noopener noreferrer"&gt;in the source repo&lt;/a&gt; to the root of your project.&lt;br&gt;
3- Build and Run the docker image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        docker build -t &amp;lt;YOUR_IMAGE_NAME&amp;gt; .
        &amp;lt;!-- List docker images and find your image ID --&amp;gt;
        docker images   
        docker run -it &amp;lt;YOU_IMAGE_ID&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4- Run the gstreamer sample app with the requisite argument&lt;br&gt;
In your running docker execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AWS_ACCESS_KEY_ID=&amp;lt;AWS_ACCESS_KEY_ID&amp;gt; \
AWS_SECRET_ACCESS_KEY=&amp;lt;AWS_SECRET_ACCESS_KEY&amp;gt; \
./kvs_gstreamer_sample &amp;lt;STREAM_NAME&amp;gt; &amp;lt;RTSP_URL&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Tip1: Make sure that you are Authenticate with your AWS credentials. Set up aws config within your Docker.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tip2: If you are using the same camera as mine, the RTSP url is typically something in this format rtsp://camera_username:camera_password@camera_ip:554/stream1&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Set Up Telegram ChatBot
&lt;/h3&gt;

&lt;p&gt;To be notified on my guests arrival, I have created a lambda function that sends me a message on Telegram application. &lt;/p&gt;

&lt;p&gt;You can simply follow instruction from &lt;a href="https://sendpulse.com/knowledge-base/chatbot/telegram/create-telegram-chatbot" rel="noopener noreferrer"&gt;this web page&lt;/a&gt; to set up your Telegram chatbot. Once the chatbot is ready, you will be provided by an API Token. As it's a secret token you can store the API Token in Amazon Secrets Manager Service to get the secret in the lambda function. The Lambda Function will use this token to send the visitors names and the music file to the telegram bot.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trouble shooting and Wrap up
&lt;/h3&gt;

&lt;p&gt;After setting everything up, it's good to go! Try out the Musical Concierge with a friend, or the next time you have someone visiting, check your Telegram messages. Here's an example of a message I got when a friend visited me over the weekend ;)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fblli7330oj4vzophr2r7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fblli7330oj4vzophr2r7.jpg" alt="telegram message sample" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tip: Remember to start your Chatbot before proceeding with deployment process&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Building your Amazon Kinesis Video Stream app gives you more control over your media stream frames. This helps prevent issues like getting the same stream records again. I recommend starting with the gstreamer sample app to save time and effort as you build on it.&lt;/p&gt;

&lt;p&gt;In this article, I wanted to show how easily you can set up a budget-friendly custom concierge. This is just the start.You can add more, like displaying a welcome message on an LED board when guests arrive or sending a fun message to their phone. Get creative, maybe even tease them about forgetting to bring your favorite beverage!&lt;/p&gt;

&lt;p&gt;I hope this guide has provided you with a solid foundation to get started with building your own Concierge. If you have any further questions or need assistance, please feel free to reach out on &lt;a href="https://www.linkedin.com/in/ronak-reyhani/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And if you are not willing to keep this experiment to avoid cost, don't forget to clean up the resources once you finished.&lt;/p&gt;

&lt;h3&gt;
  
  
  Clean up
&lt;/h3&gt;

&lt;p&gt;After you've had fun with it, now it's time to delete everything!&lt;/p&gt;

&lt;p&gt;Here's what you do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stop the Docker container.&lt;/li&gt;
&lt;li&gt;Stop &amp;amp; delete the stream processor:
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;aws rekognition stop-stream-processor --name &amp;lt;REKOGNITION_STREAM_PRODUCER&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;



&lt;p&gt;&lt;code&gt;aws rekognition delete-stream-processor --name &amp;lt;REKOGNITION_STREAM_PRODUCER&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Delete cloudformation stack.&lt;/li&gt;
&lt;li&gt;Delete the Rekognition faces collection:
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;aws rekognition delete-collection --collection-id &amp;lt;COLLECTION_ID&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>datastreaming</category>
      <category>dataanalytics</category>
      <category>aws</category>
    </item>
    <item>
      <title>Story telling App with Amazon Bedrock</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Tue, 17 Oct 2023 03:36:41 +0000</pubDate>
      <link>https://forem.com/aws-builders/story-telling-app-with-amazon-bedrock-1259</link>
      <guid>https://forem.com/aws-builders/story-telling-app-with-amazon-bedrock-1259</guid>
      <description>&lt;h2&gt;
  
  
  Initial Words
&lt;/h2&gt;

&lt;p&gt;Welcome to Part 2 of our introductory blog series! In &lt;a href="https://dev.to/ronakreyhani/an-introduction-to-amazon-bedrock-52pj"&gt;Part 1&lt;/a&gt;, we delved into the basic concepts such as Foundation Models and discovered the amazing features and capabilities of Amazon Bedrock. Now, it's time for the fun part: building your very own storytelling application with Foundation Models from Amazon Bedrock.&lt;/p&gt;

&lt;p&gt;By the time we're done here, you'll have deployed a Serverless setup with two APIs. First API will generate the story from a given topic, and the other one will illustrate each paragraph of the story. We'll be using AWS Appsync and GraphQL to make requests to these APIs and generate stories. If you're wondering how these APIs work with FM models to create stories and illustrations, that's the magic of Amazon Bedrock we'll uncover together. So, let's get started on this storytelling adventure! &lt;/p&gt;

&lt;p&gt;Now that you've got a glimpse of what we're building, let's take a moment to unravel the complexity hidden behind this simple GenAI tool. &lt;/p&gt;

&lt;p&gt;Imagine this: a user hops onto your web app and wants to create a story by giving it a topic prompt. From the user's standpoint, they expect the story to magically unfold, complete with illustrations, as quickly as they can think of it. They might want to edit and personalise the story, or even ensure that it suits the age group it's intended for. And what if they want to save and share their literary masterpiece with others?&lt;/p&gt;

&lt;p&gt;All these amazing features and optimisations are like extra layers of icing on the cake, but for our project, we're keeping things simple and focused. So, while they're fascinating possibilities, we'll save them for another time!&lt;/p&gt;

&lt;h2&gt;
  
  
  Build An Storytelling App With Me
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8iirvxw6e6ok1wlbrntp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8iirvxw6e6ok1wlbrntp.png" alt=" " width="800" height="897"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take a look at the solution diagram below! It shows you exactly how our app works at every step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The user starts by giving us a topic for their story.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When user clicks on "Generate Story," the web app sends a request to foundation model to create the story, and then it returns the generated story. The Frontend app does some cleaning on the API response and shows the story in separate paragraphs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, here's where it gets interesting. They can add illustrations to the story! In this app, I've configured the FM model to generate an image for summary of each paragraph. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;These generated images are stored in an S3 bucket, and the UI shows them to user once it gets back the S3 presigned URLs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For all the nitty-gritty details, just check out the solution architecture diagram. It's like a map that guides you through the app's awesomeness.&lt;/p&gt;

&lt;h3&gt;
  
  
  Architecture
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6rx72sdsva61m0qd7dpc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6rx72sdsva61m0qd7dpc.png" alt="solution diagram" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Web application
&lt;/h3&gt;

&lt;p&gt;For UI facing of this GenAI tool, we won't be diving into the fancy design. I've laid out the basic structure of the application. You can grab the source code from this &lt;a href="https://github.com/RonakReyhani/botRock/tree/main/storyteller/storyTeller-frontend/nextjs-app" rel="noopener noreferrer"&gt;repository&lt;/a&gt;. Feel free to give it your own unique style or add more features if you'd like. Once you've got the code, just follow the simple steps in the ReadMe file to get your app running on your computer.&lt;/p&gt;

&lt;p&gt;And if you're feeling adventurous and want to share your app with the world, you can host it on your AWS account. I won't get into the nitty-gritty details of that in this blog post, but all you really need is an Amazon S3 bucket to store your web app's resources. Then, set up Amazon CloudFront and use Route 53 to manage your domain's traffic and routing. It's not as complicated as it might sound, and it's a great way to take your project to the next level!&lt;/p&gt;

&lt;h3&gt;
  
  
  Amazon Bedrock Magician
&lt;/h3&gt;

&lt;p&gt;To set up the necessary APIs for our app to function, we'll be creating a serverless stack. You can access the complete source code in this &lt;a href="https://github.com/RonakReyhani/botRock/tree/main/storyteller/storyTeller-backend" rel="noopener noreferrer"&gt;GitHub Repo&lt;/a&gt;. In this repository, you'll find the required Lambda functions as the API resolvers, IAM Roles, Amazon Appsync, S3 Bucket and all the managed Policies listed in the "serverless.yml" file. &lt;br&gt;
To deploy the Backend resources, all you have to do is run the command specified in the "ReadMe.md" file.&lt;/p&gt;

&lt;p&gt;However, I strongly recommend that before you deploy the serverless stack, you continue reading this article. I'll be sharing code snippets from various lambdas, explaining how to define your Input Prompt, how to access the API "Request" object, and different methods for invoking the Foundation Models for both Python and Nodejs project. It's like getting a sneak peek behind the scenes!   &lt;/p&gt;
&lt;h3&gt;
  
  
  Configure the Bedrock runtime Client
&lt;/h3&gt;

&lt;p&gt;Typically, when you need to issue commands to an AWS service, the first step involves initialising the service client. In this scenario, we'll initialise the Amazon Bedrock Runtime client. &lt;/p&gt;

&lt;p&gt;Code snippets in Python and Nodejs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Implementation in Python
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="n"&gt;bedrock_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;service_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bedrock-runtime&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;region_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;us-east-1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Implementation in Nodejs&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BedrockRuntimeClient&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@aws-sdk/client-bedrock-runtime&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bedrockRuntimeClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BedrockRuntimeClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;us-east-1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Model playground
&lt;/h3&gt;

&lt;p&gt;Before Prompt engineering and constructing our request's payload, let's understand how to send requests for each Bedrock model. For that, you have two options. You can check out the Notebook examples in the Bedrock console, or you can use the model playground. &lt;/p&gt;

&lt;p&gt;In the model playground, select the model you want, configure the inference options (the model parameters will impact the result), and then click "View API Request." This allows you to copy the request and modify the input as needed.&lt;/p&gt;

&lt;p&gt;For our Generate Story API, we'll be using the "Jurassic-2 Ultra" model from the "AI21 Lab" category. Let's see how to get the api request example for this model. It's going to be a fun ride! &lt;/p&gt;

&lt;p&gt;Within the Text playground, I select the category and model: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffe90iyy4qwl7m10ifloo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffe90iyy4qwl7m10ifloo.png" alt="select model" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, type a random text, instead of invoking the model, select the "View API Request" from the screen and that will provide you with a request example to start with:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2dqqkrbbvo13brp89cl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2dqqkrbbvo13brp89cl.png" alt="request payload" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the API request payload and continue with next step where I show you how to construct your Prompt and your invoke command input. &lt;/p&gt;

&lt;h3&gt;
  
  
  Construct your Request Payload
&lt;/h3&gt;

&lt;p&gt;Now that we have the request payload, we can begin making it more versatile, allowing our model to generate stories for any given topic.&lt;/p&gt;

&lt;p&gt;Here is an example of the Text generator model API request, where we configure the "Model Id", "Model Parameters" and the "Input Prompt".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="n"&gt;kwargs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;modelId&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ai21.j2-ultra-v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;------&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt; &lt;span class="n"&gt;generator&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
  &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;contentType&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;accept&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*/*&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;prompt&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt; write a stroy up to 200 words about &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;storyTopic&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;maxTokens&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:300,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;temperature&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:0.7,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;topP&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:1,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;stopSequences&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:[],&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;countPenalty&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;scale&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:0},&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;presencePenalty&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;scale&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:0},&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;frequencyPenalty&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;scale&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:0}}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;--------&lt;/span&gt; &lt;span class="n"&gt;Body&lt;/span&gt; &lt;span class="n"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;contains&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;Model&lt;/span&gt; &lt;span class="n"&gt;Parameters&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;Input&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Implementation in Nodejs&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;constructStoryRequestPayload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;maxToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;modelId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textModelId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;contentType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;accept&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*/*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`{\"prompt\":\ &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,\"maxTokens\": &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;maxToken&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,\"temperature\":0.7,\"topP\":1,\"stopSequences\":[],\"countPenalty\":{\"scale\":0},\"presencePenalty\":{\"scale\":0},\"frequencyPenalty\":{\"scale\":0}}`&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Invoke FM for inference
&lt;/h3&gt;

&lt;p&gt;We're nearly there! It's as straightforward as this. The final step is to invoke the model (in this case, the text generator model "Jurassic-2 Ultra") and obtain inference. To get inference from models in Amazon Bedrock, we have two options. We can either use the &lt;em&gt;"invoke_model"&lt;/em&gt; method or the &lt;em&gt;"invoke_model_with_response_stream"&lt;/em&gt; method.&lt;/p&gt;

&lt;p&gt;If you're wondering about the difference, here's the scoop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With the &lt;em&gt;"invoke_model"&lt;/em&gt; method, the model won't provide any response until it has fully generated the text or completed the requested task.&lt;/li&gt;
&lt;li&gt;On the other hand, &lt;em&gt;"invoke_model_with_response_stream"&lt;/em&gt; offers a smoother and more real-time experience for users. It sends stream response payloads back to clients as the model works its magic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippets for model inference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Implementation in Python
&lt;/span&gt;
&lt;span class="c1"&gt;# invoke_model
&lt;/span&gt;&lt;span class="n"&gt;story&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bedrock_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#  invoke_model_with_response_stream
&lt;/span&gt;&lt;span class="n"&gt;story&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bedrock_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke_model_with_response_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;story&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;body)
if stream:
    for event in stream:
        chunk = event.get(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;bytes&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;completion&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Implementation in Nodejs&lt;/span&gt;

&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;invokeTextModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;maxToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// construct model API payload&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;constructStoryRequestPayload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;maxToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InvokeModelCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;// InvokeModelRequest&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bedrockRuntimeClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;command&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;story&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transformToString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="c1"&gt;// get the text body&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parsedStory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;story&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;parsedStory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With three simple steps we could generate the story from a topic! API response is returned in Json format and all we need to do is to destruct the generated text from response object.&lt;/p&gt;

&lt;h3&gt;
  
  
  Extract the generated text
&lt;/h3&gt;

&lt;p&gt;Follow the steps to extract the story content from the API response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;story_stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;story&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;story_content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;story_stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;completions&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We still need another API to complete the Story Telling app. To create illustrations based on a generated story, repeat the 3 simple steps from previous API and simply utilise the "stable-diffusion-xl-v0" model from the "Stability AI" category to generate image based on the provided content. It's that easy!&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Words
&lt;/h3&gt;

&lt;p&gt;I've always been a fan of keeping things simple and staying grounded in the fundamentals. It's a great way to uncover new ideas, explore, and learn, all while having a good time building cool stuff.&lt;/p&gt;

&lt;p&gt;In this two-part blog post, my goal was to introduce you to Amazon Bedrock, showcase its features, and demonstrate how you can easily integrate various FMs into your APIs to build amazing generative AI-powered applications.&lt;/p&gt;

&lt;p&gt;I hope you've found it valuable. Now that you have a solid foundation of Amazon Bedrock and you know how to get inference from a basic model within Amazon Bedrock in 3 simple steps feel free to build upon it and explore even further! The possibilities are endless.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>An Introduction to Amazon Bedrock</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Tue, 17 Oct 2023 03:36:07 +0000</pubDate>
      <link>https://forem.com/aws-builders/an-introduction-to-amazon-bedrock-52pj</link>
      <guid>https://forem.com/aws-builders/an-introduction-to-amazon-bedrock-52pj</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Did you catch the thrilling announcement? "Amazon Bedrock" is now officially accessible to all users. While a few incredible features of this service are still in the "Preview" stage, it is sufficient to empower teams with exciting capabilities for effortlessly creating and launching Generative AI applications.&lt;/p&gt;

&lt;p&gt;This blog post comes in two exciting parts. In Part 1, I'll dive into the core concepts and terminology, taking apart the inner mechanisms of Amazon Bedrock. Then, brace yourself for &lt;a href="https://dev.to/ronakreyhani/story-telling-app-with-amazon-bedrock-1259"&gt;Part 2&lt;/a&gt;, where I'll walk you through crafting a simple yet captivating storytelling bot with Amazon Bedrock. If you're already well-versed in the basics, feel free to jump ahead to &lt;a href="https://dev.to/ronakreyhani/story-telling-app-with-amazon-bedrock-1259"&gt;Part 2&lt;/a&gt; and embark on your creative journey! &lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Begin With The Basics
&lt;/h2&gt;

&lt;p&gt;If you share my approach of beginning with documentation, you probably have already visited the "Amazon Bedrock" homepage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjlslmk11iv88s97cjf2h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjlslmk11iv88s97cjf2h.png" alt="Amazon Bedrock Home page" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On this page, three significant phrases stand out: "Easiest way", "Scalable", and "Foundation Models". I am convinced that these attributes and characteristics are what set Amazon Bedrock apart from any other alternatives.&lt;/p&gt;

&lt;p&gt;Ever wondered why AWS calls this the "easiest" and a "Scalable" option? Well, if you're an expert in generative AI (GenAI), you've likely tasted the complexity of setting up and managing the nuts and bolts needed for a generative AI app. It's like solving a puzzle with pieces like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Picking the right computing power.&lt;/li&gt;
&lt;li&gt;Network Configurations.&lt;/li&gt;
&lt;li&gt;Ensuring model and data safety.&lt;/li&gt;
&lt;li&gt;Monitoring and Keeping an eye on the infrastructure for a reliable app.&lt;/li&gt;
&lt;li&gt;Data security&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, how does Amazon Bedrock make this complex stuff easy? Picture this: Bedrock often serves up pre-configured resources, custom-made for GenAI tasks. These ready-to-go setups come with all the software bits and pieces you need, like libraries, dependencies and tools, already installed. Plus, Bedrock integrates with AWS Managed services like Amazon S3, Amazon CloudWatch, and AWS Lambda, making tough tasks like configuring data storage, authentication, and monitoring a walk in the park for your GenAI apps.&lt;/p&gt;

&lt;p&gt;Here's the cool part: Amazon Bedrock is "Serverless." That means it can automatically grow or shrink resources as your app's popularity ebbs and flows. So, when traffic goes up, Bedrock scales up your resources, ensuring peak performance without breaking the bank. All provided data to the Bedrock is encrypted at both rest and in transit. That would give your peace of mind if you want to adopt GenAI.&lt;/p&gt;

&lt;p&gt;If I've got you excited about the ease and efficiency of GenAI apps with Amazon Bedrock, it's time to dive into the world of "Foundation Models".&lt;/p&gt;

&lt;h2&gt;
  
  
  Uncover The Magic Of Foundation Models (FMs)
&lt;/h2&gt;

&lt;p&gt;FMs are like super-smart, giant neural networks trained on massive piles of data. Instead of reinventing the AI models every time from scratch, we use FMs as a launchpad to create our own customised models in a faster and cost-effective approach. These FMs are like all-in-one champs; they can execute multiple tasks with high accuracy, like generating image or text from a simple input prompt, answering tricky questions, and even solving math puzzles. &lt;/p&gt;

&lt;p&gt;What makes FMs stand out is their versatility. Unlike regular ML models that are one-trick ponies, FMs are like jacks-of-all-trades, zipping through tasks quicker and cheaper. They're like the cool kids who make their own labels from data, thanks to something called self-supervised learning. This sets them apart from the old-school ML models, whether they were supervised or flying solo without supervision (unsupervised learning)!&lt;/p&gt;

&lt;h2&gt;
  
  
  Demystify Amazon Bedrock
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Availability
&lt;/h3&gt;

&lt;p&gt;As of writing this blog post, Amazon Bedrock is accessible in four regions, as listed below. But keep in mind that by the time you're reading this, AWS might have expanded its availability to additional regions. So, always stay tuned for the latest updates!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvogewm4co3ytw89isjj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvogewm4co3ytw89isjj.png" alt="Bedrock region availability" width="321" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bedrock Base Foundation Model Choices
&lt;/h3&gt;

&lt;p&gt;If you're new to Amazon Bedrock and you're diving into the "Base Models" within your AWS console, you might notice a warning next to the listed models. By default, your Amazon Bedrock doesn't come with access to these base FMs. To use them, you'll need to request access first.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbbofqj3as4ydrhe3gbws.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbbofqj3as4ydrhe3gbws.png" alt="base model availability" width="800" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make this happen, head to your AWS Amazon Bedrock console and navigate to "Model Access." There, you can pick the models you want to use and send in an access request for them. After a little while, maybe a few minutes or occasionally a few hours, you'll see those models go from "Pending" to "Access granted," just like in the screenshot below. Keep in mind that Model access is provided on a per-region basis. If you want models available in multiple regions, you'll need to request access for each region separately.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3xpt0mw7scyv42r07j9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3xpt0mw7scyv42r07j9.png" alt="request model access" width="800" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to explore the list of available Foundation Models (FMs) for Amazon Bedrock and discover their individual use cases. &lt;/p&gt;

&lt;p&gt;Pricing for each model is determined by the pricing mode you've chosen, whether it's On-Demand or Provisioned. Additionally, it's influenced by factors like the length of the generated tokens and other considerations. For detailed pricing information, you can refer to &lt;a href="https://aws.amazon.com/bedrock/pricing/" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fine-Tune a Foundation Model
&lt;/h3&gt;

&lt;p&gt;Isn't this exciting? The best part is that we're not restricted to just using Base Models. We have the flexibility to supply a labeled dataset, initiate a tuning job, and once we're satisfied with the model's performance and accuracy, we can seamlessly utilise the fine-tuned model for inference, just as easily as working with the Base Models.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bedrock Agent (In Preview)
&lt;/h3&gt;

&lt;p&gt;I must admit, this is my absolute favourite feature, and I'm eagerly awaiting the day when AWS announces it's available to everyone, perhaps at Re:Invent 2024!&lt;/p&gt;

&lt;p&gt;If you're not sure what an agent means in the world of Generative AI, I've put together a brief &lt;a href="https://blog.mechanicalrock.io/2023/07/04/LLM-Transformers.html" rel="noopener noreferrer"&gt;blog post&lt;/a&gt; explaining Agents and Transformers. Agents have the incredible power to expand the capabilities of Foundation Models. They can grasp all sorts of user requests, tackle even the most complex ones by breaking them down into smaller tasks, and then take action to fulfill those requests. If you want to learn how to make your own Agent for Amazon Bedrock, you're in luck! Check out this fantastic &lt;a href="https://aws.amazon.com/blogs/aws/preview-enable-foundation-models-to-complete-tasks-with-agents-for-amazon-bedrock/" rel="noopener noreferrer"&gt;article&lt;/a&gt; for all the details.&lt;/p&gt;

&lt;h3&gt;
  
  
  Knowledge Base (In Preview)
&lt;/h3&gt;

&lt;p&gt;Like the Bedrock agent, this feature is still in "Preview". Creating agents for Amazon Bedrock offers a big advantage: it allows secure connections between FMs and your company's data sources. This means Bedrock can tap into additional datasets, resulting in more precise answers.&lt;/p&gt;

&lt;p&gt;If you've got Preview access to Amazon Bedrock, don't hesitate any longer. Jump into your AWS console and follow this detailed &lt;a href="https://aws.amazon.com/blogs/aws/preview-connect-foundation-models-to-your-company-data-sources-with-agents-for-amazon-bedrock/" rel="noopener noreferrer"&gt;blog post&lt;/a&gt; to learn how to kickstart the Knowledge Base for Amazon Bedrock.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap Up
&lt;/h2&gt;

&lt;p&gt;While Amazon Bedrock is still evolving, it's been a game-changer for sparking our creativity and making it easy and cost-effective to build advanced generative AI apps. Personally, I can't wait to try out Amazon Bedrock Agent and its Knowledge Base features; they promise even more exciting possibilities.&lt;/p&gt;

&lt;p&gt;Now that you've got the basics of this service and its models, let's get hands-on. Follow along in &lt;a href="https://dev.to/ronakreyhani/story-telling-app-with-amazon-bedrock-1259"&gt;Part 2&lt;/a&gt; of this article, where I'll guide you through creating a storytelling app using Amazon Bedrock and some other cool Amazon services. It's time to bring your ideas to life!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Story telling App with Amazon Bedrock</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Sun, 15 Oct 2023 17:53:52 +0000</pubDate>
      <link>https://forem.com/ronakreyhani/story-telling-app-with-amazon-bedrock-2af9</link>
      <guid>https://forem.com/ronakreyhani/story-telling-app-with-amazon-bedrock-2af9</guid>
      <description>&lt;h2&gt;
  
  
  Initial Words
&lt;/h2&gt;

&lt;p&gt;Welcome to Part 2 of our introductory blog series! In &lt;a href="https://dev.to/ronakreyhani/demystifying-amazon-bedrock-3hp0"&gt;Part 1&lt;/a&gt;, we delved into the basic concepts such as Foundation Models and discovered the amazing features and capabilities of Amazon Bedrock. Now, it's time for the fun part: building your very own storytelling application with Foundation Models from Amazon Bedrock.&lt;/p&gt;

&lt;p&gt;By the time we're done here, you'll have deployed a Serverless setup with two APIs. First API will generate the story from a given topic, and the other one will illustrate each paragraph of the story. We'll be using AWS Appsync and GraphQL to make requests to these APIs and generate stories. If you're wondering how these APIs work with FM models to create stories and illustrations, that's the magic of Amazon Bedrock we'll uncover together. So, let's get started on this storytelling adventure! &lt;/p&gt;

&lt;p&gt;Now that you've got a glimpse of what we're building, let's take a moment to unravel the complexity hidden behind this simple GenAI tool. &lt;/p&gt;

&lt;p&gt;Imagine this: a user hops onto your web app and wants to create a story by giving it a topic prompt. From the user's standpoint, they expect the story to magically unfold, complete with illustrations, as quickly as they can think of it. They might want to edit and personalise the story, or even ensure that it suits the age group it's intended for. And what if they want to save and share their literary masterpiece with others?&lt;/p&gt;

&lt;p&gt;All these amazing features and optimisations are like extra layers of icing on the cake, but for our project, we're keeping things simple and focused. So, while they're fascinating possibilities, we'll save them for another time!&lt;/p&gt;

&lt;h2&gt;
  
  
  Build An Storytelling App With Me
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8iirvxw6e6ok1wlbrntp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8iirvxw6e6ok1wlbrntp.png" alt=" " width="800" height="897"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take a look at the solution diagram below! It shows you exactly how our app works at every step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The user starts by giving us a topic for their story.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When user clicks on "Generate Story," the web app sends a request to foundation model to create the story, and then it returns the generated story. The Frontend app does some cleaning on the API response and shows the story in separate paragraphs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, here's where it gets interesting. They can add illustrations to the story! In this app, I've configured the FM model to generate an image for summary of each paragraph. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;These generated images are stored in an S3 bucket, and the UI shows them to user once it gets back the S3 presigned URLs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For all the nitty-gritty details, just check out the solution architecture diagram. It's like a map that guides you through the app's awesomeness.&lt;/p&gt;

&lt;h3&gt;
  
  
  Architecture
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6rx72sdsva61m0qd7dpc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6rx72sdsva61m0qd7dpc.png" alt="solution diagram" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Web application
&lt;/h3&gt;

&lt;p&gt;For UI facing of this GenAI tool, we won't be diving into the fancy design. I've laid out the basic structure of the application. You can grab the source code from this &lt;a href="https://github.com/RonakReyhani/botRock/tree/main/storyteller/storyTeller-frontend/nextjs-app" rel="noopener noreferrer"&gt;repository&lt;/a&gt;. Feel free to give it your own unique style or add more features if you'd like. Once you've got the code, just follow the simple steps in the ReadMe file to get your app running on your computer.&lt;/p&gt;

&lt;p&gt;And if you're feeling adventurous and want to share your app with the world, you can host it on your AWS account. I won't get into the nitty-gritty details of that in this blog post, but all you really need is an Amazon S3 bucket to store your web app's resources. Then, set up Amazon CloudFront and use Route 53 to manage your domain's traffic and routing. It's not as complicated as it might sound, and it's a great way to take your project to the next level!&lt;/p&gt;

&lt;h3&gt;
  
  
  Amazon Bedrock Magician
&lt;/h3&gt;

&lt;p&gt;To set up the necessary APIs for our app to function, we'll be creating a serverless stack. You can access the complete source code in this &lt;a href="https://github.com/RonakReyhani/botRock/tree/main/storyteller/storyTeller-backend" rel="noopener noreferrer"&gt;GitHub Repo&lt;/a&gt;. In this repository, you'll find the required Lambda functions as the API resolvers, IAM Roles, Amazon Appsync, S3 Bucket and all the managed Policies listed in the "serverless.yml" file. &lt;br&gt;
To deploy the Backend resources, all you have to do is run the command specified in the "ReadMe.md" file.&lt;/p&gt;

&lt;p&gt;However, I strongly recommend that before you deploy the serverless stack, you continue reading this article. I'll be sharing code snippets from various lambdas, explaining how to define your Input Prompt, how to access the API "Request" object, and different methods for invoking the Foundation Models for both Python and Nodejs project. It's like getting a sneak peek behind the scenes!   &lt;/p&gt;
&lt;h3&gt;
  
  
  Configure the Bedrock runtime Client
&lt;/h3&gt;

&lt;p&gt;Typically, when you need to issue commands to an AWS service, the first step involves initialising the service client. In this scenario, we'll initialise the Amazon Bedrock Runtime client. &lt;/p&gt;

&lt;p&gt;Code snippets in Python and Nodejs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Implementation in Python
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="n"&gt;bedrock_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;service_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bedrock-runtime&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;region_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;us-east-1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Implementation in Nodejs&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BedrockRuntimeClient&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@aws-sdk/client-bedrock-runtime&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bedrockRuntimeClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BedrockRuntimeClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;us-east-1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Model playground
&lt;/h3&gt;

&lt;p&gt;Before Prompt engineering and constructing our request's payload, let's understand how to send requests for each Bedrock model. For that, you have two options. You can check out the Notebook examples in the Bedrock console, or you can use the model playground. &lt;/p&gt;

&lt;p&gt;In the model playground, select the model you want, configure the inference options (the model parameters will impact the result), and then click "View API Request." This allows you to copy the request and modify the input as needed.&lt;/p&gt;

&lt;p&gt;For our Generate Story API, we'll be using the "Jurassic-2 Ultra" model from the "AI21 Lab" category. Let's see how to get the api request example for this model. It's going to be a fun ride! &lt;/p&gt;

&lt;p&gt;Within the Text playground, I select the category and model: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffe90iyy4qwl7m10ifloo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffe90iyy4qwl7m10ifloo.png" alt="select model" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, type a random text, instead of invoking the model, select the "View API Request" from the screen and that will provide you with a request example to start with:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2dqqkrbbvo13brp89cl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2dqqkrbbvo13brp89cl.png" alt="request payload" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the API request payload and continue with next step where I show you how to construct your Prompt and your invoke command input. &lt;/p&gt;

&lt;h3&gt;
  
  
  Construct your Request Payload
&lt;/h3&gt;

&lt;p&gt;Now that we have the request payload, we can begin making it more versatile, allowing our model to generate stories for any given topic.&lt;/p&gt;

&lt;p&gt;Here is an example of the Text generator model API request, where we configure the "Model Id", "Model Parameters" and the "Input Prompt".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="n"&gt;kwargs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;modelId&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ai21.j2-ultra-v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;------&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt; &lt;span class="n"&gt;generator&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
  &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;contentType&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;accept&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*/*&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;prompt&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt; write a stroy up to 200 words about &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;storyTopic&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;maxTokens&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:300,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;temperature&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:0.7,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;topP&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:1,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;stopSequences&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:[],&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;countPenalty&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;scale&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:0},&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;presencePenalty&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;scale&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:0},&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;frequencyPenalty&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;scale&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;:0}}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;--------&lt;/span&gt; &lt;span class="n"&gt;Body&lt;/span&gt; &lt;span class="n"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;contains&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;Model&lt;/span&gt; &lt;span class="n"&gt;Parameters&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;Input&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Implementation in Nodejs&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;constructStoryRequestPayload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;maxToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;modelId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textModelId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;contentType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;accept&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*/*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`{\"prompt\":\ &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,\"maxTokens\": &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;maxToken&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,\"temperature\":0.7,\"topP\":1,\"stopSequences\":[],\"countPenalty\":{\"scale\":0},\"presencePenalty\":{\"scale\":0},\"frequencyPenalty\":{\"scale\":0}}`&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Invoke FM for inference
&lt;/h3&gt;

&lt;p&gt;We're nearly there! It's as straightforward as this. The final step is to invoke the model (in this case, the text generator model "Jurassic-2 Ultra") and obtain inference. To get inference from models in Amazon Bedrock, we have two options. We can either use the &lt;em&gt;"invoke_model"&lt;/em&gt; method or the &lt;em&gt;"invoke_model_with_response_stream"&lt;/em&gt; method.&lt;/p&gt;

&lt;p&gt;If you're wondering about the difference, here's the scoop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With the &lt;em&gt;"invoke_model"&lt;/em&gt; method, the model won't provide any response until it has fully generated the text or completed the requested task.&lt;/li&gt;
&lt;li&gt;On the other hand, &lt;em&gt;"invoke_model_with_response_stream"&lt;/em&gt; offers a smoother and more real-time experience for users. It sends stream response payloads back to clients as the model works its magic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code snippets for model inference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Implementation in Python
&lt;/span&gt;
&lt;span class="c1"&gt;# invoke_model
&lt;/span&gt;&lt;span class="n"&gt;story&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bedrock_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#  invoke_model_with_response_stream
&lt;/span&gt;&lt;span class="n"&gt;story&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bedrock_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke_model_with_response_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;story&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;body)
if stream:
    for event in stream:
        chunk = event.get(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;bytes&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;completion&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Implementation in Nodejs&lt;/span&gt;

&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;invokeTextModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;maxToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// construct model API payload&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;constructStoryRequestPayload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;maxToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InvokeModelCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;// InvokeModelRequest&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bedrockRuntimeClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;command&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;story&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transformToString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="c1"&gt;// get the text body&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parsedStory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;story&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;parsedStory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With three simple steps we could generate the story from a topic! API response is returned in Json format and all we need to do is to destruct the generated text from response object.&lt;/p&gt;

&lt;h3&gt;
  
  
  Extract the generated text
&lt;/h3&gt;

&lt;p&gt;Follow the steps to extract the story content from the API response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;story_stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;story&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;story_content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;story_stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;completions&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We still need another API to complete the Story Telling app. To create illustrations based on a generated story, repeat the 3 simple steps from previous API and simply utilise the "stable-diffusion-xl-v0" model from the "Stability AI" category to generate image based on the provided content. It's that easy!&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Words
&lt;/h3&gt;

&lt;p&gt;I've always been a fan of keeping things simple and staying grounded in the fundamentals. It's a great way to uncover new ideas, explore, and learn, all while having a good time building cool stuff.&lt;/p&gt;

&lt;p&gt;In this two-part blog post, my goal was to introduce you to Amazon Bedrock, showcase its features, and demonstrate how you can easily integrate various FMs into your APIs to build amazing generative AI-powered applications.&lt;/p&gt;

&lt;p&gt;I hope you've found it valuable. Now that you have a solid foundation of Amazon Bedrock and you know how to get inference from a basic model within Amazon Bedrock in 3 simple steps feel free to build upon it and explore even further! The possibilities are endless.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>An Introduction to Amazon Bedrock</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Mon, 09 Oct 2023 04:38:39 +0000</pubDate>
      <link>https://forem.com/ronakreyhani/demystifying-amazon-bedrock-3hp0</link>
      <guid>https://forem.com/ronakreyhani/demystifying-amazon-bedrock-3hp0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Did you catch the thrilling announcement? "Amazon Bedrock" is now officially accessible to all users. While a few incredible features of this service are still in the "Preview" stage, it is sufficient to empower teams with exciting capabilities for effortlessly creating and launching Generative AI applications.&lt;/p&gt;

&lt;p&gt;This blog post comes in two exciting parts. In Part 1, I'll dive into the core concepts and terminology, taking apart the inner mechanisms of Amazon Bedrock. Then, brace yourself for &lt;a href="https://dev.to/ronakreyhani/story-telling-app-with-amazon-bedrock-2af9"&gt;Part 2&lt;/a&gt;, where I'll walk you through crafting a simple yet captivating storytelling bot with Amazon Bedrock. If you're already well-versed in the basics, feel free to jump ahead to &lt;a href="https://dev.to/ronakreyhani/story-telling-app-with-amazon-bedrock-2af9"&gt;Part 2&lt;/a&gt; and embark on your creative journey! &lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Begin With The Basics
&lt;/h2&gt;

&lt;p&gt;If you share my approach of beginning with documentation, you probably have already visited the "Amazon Bedrock" homepage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjlslmk11iv88s97cjf2h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjlslmk11iv88s97cjf2h.png" alt="Amazon Bedrock Home page" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On this page, three significant phrases stand out: "Easiest way", "Scalable", and "Foundation Models". I am convinced that these attributes and characteristics are what set Amazon Bedrock apart from any other alternatives.&lt;/p&gt;

&lt;p&gt;Ever wondered why AWS calls this the "easiest" and a "Scalable" option? Well, if you're an expert in generative AI (GenAI), you've likely tasted the complexity of setting up and managing the nuts and bolts needed for a generative AI app. It's like solving a puzzle with pieces like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Picking the right computing power.&lt;/li&gt;
&lt;li&gt;Network Configurations.&lt;/li&gt;
&lt;li&gt;Ensuring model and data safety.&lt;/li&gt;
&lt;li&gt;Monitoring and Keeping an eye on the infrastructure for a reliable app.&lt;/li&gt;
&lt;li&gt;Data security&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, how does Amazon Bedrock make this complex stuff easy? Picture this: Bedrock often serves up pre-configured resources, custom-made for GenAI tasks. These ready-to-go setups come with all the software bits and pieces you need, like libraries, dependencies and tools, already installed. Plus, Bedrock integrates with AWS Managed services like Amazon S3, Amazon CloudWatch, and AWS Lambda, making tough tasks like configuring data storage, authentication, and monitoring a walk in the park for your GenAI apps.&lt;/p&gt;

&lt;p&gt;Here's the cool part: Amazon Bedrock is "Serverless." That means it can automatically grow or shrink resources as your app's popularity ebbs and flows. So, when traffic goes up, Bedrock scales up your resources, ensuring peak performance without breaking the bank. All provided data to the Bedrock is encrypted at both rest and in transit. That would give your peace of mind if you want to adopt GenAI.&lt;/p&gt;

&lt;p&gt;If I've got you excited about the ease and efficiency of GenAI apps with Amazon Bedrock, it's time to dive into the world of "Foundation Models".&lt;/p&gt;

&lt;h2&gt;
  
  
  Uncover The Magic Of Foundation Models (FMs)
&lt;/h2&gt;

&lt;p&gt;FMs are like super-smart, giant neural networks trained on massive piles of data. Instead of reinventing the AI models every time from scratch, we use FMs as a launchpad to create our own customised models in a faster and cost-effective approach. These FMs are like all-in-one champs; they can execute multiple tasks with high accuracy, like generating image or text from a simple input prompt, answering tricky questions, and even solving math puzzles. &lt;/p&gt;

&lt;p&gt;What makes FMs stand out is their versatility. Unlike regular ML models that are one-trick ponies, FMs are like jacks-of-all-trades, zipping through tasks quicker and cheaper. They're like the cool kids who make their own labels from data, thanks to something called self-supervised learning. This sets them apart from the old-school ML models, whether they were supervised or flying solo without supervision (unsupervised learning)!&lt;/p&gt;

&lt;h2&gt;
  
  
  Demystify Amazon Bedrock
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Availability
&lt;/h3&gt;

&lt;p&gt;As of writing this blog post, Amazon Bedrock is accessible in four regions, as listed below. But keep in mind that by the time you're reading this, AWS might have expanded its availability to additional regions. So, always stay tuned for the latest updates!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvogewm4co3ytw89isjj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvogewm4co3ytw89isjj.png" alt="Bedrock region availability" width="321" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bedrock Base Foundation Model Choices
&lt;/h3&gt;

&lt;p&gt;If you're new to Amazon Bedrock and you're diving into the "Base Models" within your AWS console, you might notice a warning next to the listed models. By default, your Amazon Bedrock doesn't come with access to these base FMs. To use them, you'll need to request access first.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbbofqj3as4ydrhe3gbws.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbbofqj3as4ydrhe3gbws.png" alt="base model availability" width="800" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make this happen, head to your AWS Amazon Bedrock console and navigate to "Model Access." There, you can pick the models you want to use and send in an access request for them. After a little while, maybe a few minutes or occasionally a few hours, you'll see those models go from "Pending" to "Access granted," just like in the screenshot below. Keep in mind that Model access is provided on a per-region basis. If you want models available in multiple regions, you'll need to request access for each region separately.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3xpt0mw7scyv42r07j9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3xpt0mw7scyv42r07j9.png" alt="request model access" width="800" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to explore the list of available Foundation Models (FMs) for Amazon Bedrock and discover their individual use cases. &lt;/p&gt;

&lt;p&gt;Pricing for each model is determined by the pricing mode you've chosen, whether it's On-Demand or Provisioned. Additionally, it's influenced by factors like the length of the generated tokens and other considerations. For detailed pricing information, you can refer to &lt;a href="https://aws.amazon.com/bedrock/pricing/" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fine-Tune a Foundation Model
&lt;/h3&gt;

&lt;p&gt;Isn't this exciting? The best part is that we're not restricted to just using Base Models. We have the flexibility to supply a labeled dataset, initiate a tuning job, and once we're satisfied with the model's performance and accuracy, we can seamlessly utilise the fine-tuned model for inference, just as easily as working with the Base Models.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bedrock Agent (In Preview)
&lt;/h3&gt;

&lt;p&gt;I must admit, this is my absolute favourite feature, and I'm eagerly awaiting the day when AWS announces it's available to everyone, perhaps at Re:Invent 2024!&lt;/p&gt;

&lt;p&gt;If you're not sure what an agent means in the world of Generative AI, I've put together a brief &lt;a href="https://blog.mechanicalrock.io/2023/07/04/LLM-Transformers.html" rel="noopener noreferrer"&gt;blog post&lt;/a&gt; explaining Agents and Transformers. Agents have the incredible power to expand the capabilities of Foundation Models. They can grasp all sorts of user requests, tackle even the most complex ones by breaking them down into smaller tasks, and then take action to fulfill those requests. If you want to learn how to make your own Agent for Amazon Bedrock, you're in luck! Check out this fantastic &lt;a href="https://aws.amazon.com/blogs/aws/preview-enable-foundation-models-to-complete-tasks-with-agents-for-amazon-bedrock/" rel="noopener noreferrer"&gt;article&lt;/a&gt; for all the details.&lt;/p&gt;

&lt;h3&gt;
  
  
  Knowledge Base (In Preview)
&lt;/h3&gt;

&lt;p&gt;Like the Bedrock agent, this feature is still in "Preview". Creating agents for Amazon Bedrock offers a big advantage: it allows secure connections between FMs and your company's data sources. This means Bedrock can tap into additional datasets, resulting in more precise answers.&lt;/p&gt;

&lt;p&gt;If you've got Preview access to Amazon Bedrock, don't hesitate any longer. Jump into your AWS console and follow this detailed &lt;a href="https://aws.amazon.com/blogs/aws/preview-connect-foundation-models-to-your-company-data-sources-with-agents-for-amazon-bedrock/" rel="noopener noreferrer"&gt;blog post&lt;/a&gt; to learn how to kickstart the Knowledge Base for Amazon Bedrock.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap Up
&lt;/h2&gt;

&lt;p&gt;While Amazon Bedrock is still evolving, it's been a game-changer for sparking our creativity and making it easy and cost-effective to build advanced generative AI apps. Personally, I can't wait to try out Amazon Bedrock Agent and its Knowledge Base features; they promise even more exciting possibilities.&lt;/p&gt;

&lt;p&gt;Now that you've got the basics of this service and its models, let's get hands-on. Follow along in &lt;a href=""&gt;Part 2&lt;/a&gt; of this article, where I'll guide you through creating a storytelling app using Amazon Bedrock and some other cool Amazon services. It's time to bring your ideas to life!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Self Service Learning Platform With Hugging Face Transformers!</title>
      <dc:creator>NaDia</dc:creator>
      <pubDate>Fri, 30 Jun 2023 19:58:32 +0000</pubDate>
      <link>https://forem.com/ronakreyhani/self-service-learning-platform-with-hugging-face-transformers-i1</link>
      <guid>https://forem.com/ronakreyhani/self-service-learning-platform-with-hugging-face-transformers-i1</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;h4&gt;
  
  
  About Quizify
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;Self-Service Learning platform&lt;/code&gt; can be converted to an innovative app designed to revolutionise your learning experience. With this powerful tool, users can effortlessly generate custom quizzes based on any PDF file they download from the web. Gone are the days of tedious manual summarisation and translation! this potential application leverages the cutting-edge capabilities of Hugging Face transformers to simplify the entire process. Once you've obtained a PDF, simply import it into the app and watch as the magic unfolds.&lt;/p&gt;

&lt;p&gt;As students, parents, or job seekers, we often encounter situations where we need to summarise a document promptly and prepare questions for ourselves or our children. This inspired the concept of a self-service learning platform. &lt;/p&gt;

&lt;p&gt;This learning platform empowers you to retrieve files from the internet and summarise the document with ease. Not only that, but this app also offers built-in translation functionality, allowing you to understand the content in your preferred language. &lt;/p&gt;

&lt;p&gt;But the true power of our app lies in its ability to transform your summarised and translated document into an interactive question-answer service. By analysing the text and extracting relevant information, the app generates thought-provoking questions that test your understanding of the material. Whether you're a student striving for academic excellence or a professional looking to enhance your knowledge, the Self Service Quiz Generator platform is your go-to tool for efficient and engaging learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Motivation
&lt;/h3&gt;

&lt;p&gt;Words like &lt;em&gt;ChatGPT, Generative AI, LLM, LangChain, Hugging Face, Transformers,&lt;/em&gt; and many others have become part of our daily vocabulary, frequently heard and mentioned throughout the day.&lt;/p&gt;

&lt;p&gt;Regrettably, it is challenging to keep pace with the rapid advancements in technology and acquire knowledge about every new development introduced in the tech world.&lt;/p&gt;

&lt;p&gt;Being a part of the AWS Community Builder offers numerous advantages, one of which is the opportunity to participate in a variety of challenges ranging from openMic sessions to Hackathons like the current one. Each challenge provides a valuable learning experience. In this instance, we were presented with the #AiHackathon challenge to develop a tool utilising the &lt;a href="https://huggingface.co/docs/transformers/main/transformers_agents" rel="noopener noreferrer"&gt;Transformer Tools&lt;/a&gt; framework. &lt;/p&gt;

&lt;p&gt;My unwavering desire to learn about ML concepts and the constantly evolving landscape of ML and AI has made it impossible for me to let go of this incredible learning opportunity!&lt;/p&gt;

&lt;h3&gt;
  
  
  Process of shaping my idea
&lt;/h3&gt;

&lt;p&gt;Prior to this challenge, I had no prior knowledge of Hugging Face Transformers and agents. To familiarise myself with the concept of transformers, I began by exploring tutorials and educational resources. As I delved deeper, I contemplated how to harness the immense potential of the Large Language Model technology.&lt;/p&gt;

&lt;p&gt;With a more comprehensive understanding of the topic at hand, I embarked on a brainstorming session. After finalising the idea, I focused on outlining the features, which led me to develop this tool incorporating six custom Transformer Tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv84702vmidzysdf5pei4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv84702vmidzysdf5pei4.png" alt="Quizify Custom Tools" width="698" height="755"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Downloader Service
&lt;/h4&gt;

&lt;p&gt;To begin, You should provide a valid URL for your PDF resource.&lt;/p&gt;

&lt;p&gt;If you choose to enter a URL, The Hugging Face Agent will seamlessly download the file for you. This process utilises a custom tool known as the &lt;code&gt;download_file_tool&lt;/code&gt; working silently behind the scenes to retrieve the document.&lt;/p&gt;

&lt;p&gt;Currently, This proof of concept exclusively supports PDF files at this stage.&lt;/p&gt;

&lt;p&gt;As an alternative, you have the option to upload your PDF file. Our agent will utilise a specialised tool called &lt;code&gt;read_file_tool&lt;/code&gt; to process and extract the content from the document. The extracted information will be saved for further use within the platform.&lt;/p&gt;

&lt;h4&gt;
  
  
  Summarisation Service
&lt;/h4&gt;

&lt;p&gt;Get ready to dive into the exciting features of our app. How about downloading a summarisation of your uploaded document or web content? Let's embark on this thrilling journey together!"&lt;br&gt;
By asking the agent to summarise the file content, the Hugging Face agent will generate a summary of your document.&lt;/p&gt;

&lt;p&gt;Please note that the summarisation model used by the agent is the &lt;code&gt;facebook/bart-large-cnn&lt;/code&gt;, the results may not be perfect. If your document is excessively large, there is a chance it may encounter difficulties or exhibit unexpected behaviour while processing.&lt;/p&gt;

&lt;p&gt;Here is an example how I have leveraged Transformers pipeline to summarise a large document:&lt;/p&gt;

&lt;h4&gt;
  
  
  Translation Service
&lt;/h4&gt;

&lt;p&gt;Perhaps English is your second language, just like mine! Or you have found an amazing document to read but not in the language that you are familiar with, don't worry, I've got your back 😉. With this tool, you can select between &lt;code&gt;Italian&lt;/code&gt;, &lt;code&gt;French&lt;/code&gt;, and &lt;code&gt;Spanish&lt;/code&gt; languages. Not only that, but you can also have the summary translated into your preferred language for better understanding.&lt;/p&gt;

&lt;h4&gt;
  
  
  Text-To-Speech Service
&lt;/h4&gt;

&lt;p&gt;In addition to all we mentioned so far, if you are keen to listen to the summary or the original uploaded content, in this platform you will be able to generate audio from the file.&lt;/p&gt;

&lt;h4&gt;
  
  
  Quiz Generator Service
&lt;/h4&gt;

&lt;p&gt;Have you studied the summary carefully? Great! That means you're ready, right? Now, let's ask our Hugging Face agent to generate some engaging multiple-choice questions for you! Get ready to put your knowledge to the test!&lt;/p&gt;

&lt;p&gt;You have the freedom to choose the language in which you want to be examined! Simply select your desired language option. Additionally, you can specify the number of questions you would like in your requested exam. Tailor the examination experience according to your preferences!&lt;br&gt;
Once the agent has gathered this information, it will utilise another specialised tool called &lt;code&gt;quiz_generator_tool&lt;/code&gt; to generate the quiz for you. This tool is specifically designed to create dynamic and engaging quizzes based on your selected preferences. Sit back and let the quiz generation process unfold!&lt;/p&gt;

&lt;h3&gt;
  
  
  Outcome and demonstration of Jupyter Notebook
&lt;/h3&gt;

&lt;p&gt;The full Jupyter Notebook is available for reference at the provided &lt;a href="https://github.com/RonakReyhani/quizify" rel="noopener noreferrer"&gt;Link&lt;/a&gt;. To begin, start by installing the necessary dependencies and logging in to the Hugging Face hub. Afterward, the remaining steps are straightforward and easy to follow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenges I faced!
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When I began my learning journey, I sought answers to all my "Why" and "How" questions. However, since it's a relatively new topic, the availability of learning materials was limited. Therefore, I had to delve into documentation and explore relevant forums to find the information I needed. For instance, I had to search for guidance on configuring a custom Prompt run_template, such as "How to configure a custom Prompt run_template."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Error message notebook_login! So I ended up using the &lt;code&gt;login&lt;/code&gt; class instead of &lt;code&gt;notebook_login&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;ValueError(“Invalid token passed.”)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;By removing PreTools from the agent's toolBox, the agent's confusion can be reduced. However, it's important to note that the agent will still search for default tools, especially if they are within the same context, such as translation or summarisations.&lt;/li&gt;
&lt;li&gt;Unsuccessful attempts on using Streamlit and Vercel  as a fast and quick way to add a nice user interface in the such short time. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2v5qi18dbi23wnrqf2f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2v5qi18dbi23wnrqf2f.png" alt="streamlit error" width="639" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Managing dependencies for the tools proved to be a significant factor that discouraged me from considering combinations like AppSync/API Gateway and Lambda. Instead, I made a straightforward decision to implement the solution using a Jupyter Notebook, which allowed for easier dependency management.&lt;/li&gt;
&lt;li&gt;LLM models are so sensitive with "Text" as their input! Prompt engineering is a "Thing".&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is next?
&lt;/h3&gt;

&lt;p&gt;There are numerous ways to enhance this tool. First and foremost, it would be beneficial to transform the concept into an application by incorporating a user interface and providing proper API references to various tools. Additionally, the models can be fine-tuned and retrained to enhance the quality of each service, such as the Summarisation and Quiz Generator Tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reflection
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy131vqo7j9zcmbcy5vbm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy131vqo7j9zcmbcy5vbm.png" alt="Architecture" width="582" height="842"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Throughout this entire journey, I have gained a wealth of knowledge about transformers and have witnessed the immense power of the Agent. I have successfully trained the most complex LLM Model and integrated it into the agent's toolbox. This has sparked my imagination, as I contemplate the vast possibilities of designing efficient systems with the agent at the centre, orchestrating decoupled tasks.&lt;/p&gt;

&lt;p&gt;As the AiHackathon draws to a close, my enthusiasm remains undiminished, compelling me to revisit each challenge and seek their solutions one by one. I find myself continuously envisioning the end-to-end architecture of this solution in my mind. It is now time to bring this vision out of my head and construct it meticulously as a fully-fledged application.&lt;/p&gt;

</description>
      <category>transformer</category>
      <category>huggingface</category>
      <category>sagemaker</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
