API key authentication is a common method for securing APIs by controlling access to them. It’s important to note that API keys are great for authentication, but further development should be made to ensure proper authorization at the business level. API keys do not ensure that the correct permissions are being enforced, only that the user has access to the API. Regardless, let’s get…
On May 30th, 2024, Amazon announced the release of the Bedrock Converse API. This API is designed to provide a consistent experience for “conversing” with Amazon Bedrock models. The API supports: Conversations with multiple turns System messages Tool use Image and text input In this post, we’ll walk through how to use the Amazon Bedrock Converse API with the Claude Haiku…
DynamoDB supports an UpdateItem operation that modifies an existing or creates a new item. The UpdateItem accepts an UpdateExpression that dictates which operations will occur on the specified item. In this post, we’ll explore how to perform multiple operations including within a clause/keyword and with multiple clauses/keywords. What is an update expression An update expression supports…
Typically, AWS recommends leveraging an existing service offering such as Amazon Comprehend to detect and redact PII. However, this post explores an alternative solution using Amazon Bedrock. This is possible using the Claude, Anthropic’s large langauge model, and their publicly available prompt library. In our case, we’ll leverage the PII purifier prompt that is maintained by their…
On April 4th, 2024, Anthropic released official support for tool use through their API. This feature allows developers to define one or more tools that include parameters, descriptions, and schema definitions for Claude to process. In this post, we’ll go over how to leverage these tools using the Python Anthropic SDK. Claude with tools example in Python Firstly, ensure that your Anthropic…
The primary motive for writing this article is to address the common error I repeatedly received while troubleshooting event filters: Invalid filter pattern definition. (Service: AWSLambda; Status Code: 400; Error Code: InvalidParameterValueException For my case, the goal was to invoke an AWS Lambda function via a DynamoDB stream. What are Lambda Event Filters Lambda event filters allow developers…
In November 2023, I wrote a post describing how to deploy a lambda function with a function url in Python. For this post, I want to showcase how streamlined and practical it is to deploy a “Lambdalith” (a single Lambda function) that contains an entire API. What this means: No API Gateway API requests can take longer than 30 seconds Faster deployments Local testing without cloud…
With the recent release of the Claude 3 family, this was the perfect opportunity to use the Claude API access that I was recently granted. The Claude 3 family boasts a huge improvement from the prior family, Claude 2. The introductory post goes into greater detail. In this post, we’ll explore how to invoke Claude 3 Opus using the Anthropic SDK. Getting started For the purposes of this post,…
On March 4th, 2024, the Claude 3 Sonnet foundational model was made available in Amazon Bedrock. Not only is the model a major improvement over the Claude 2.0 family, but it allows for vision input. In the post, we’ll explore how to invoke Claude 3 Sonnet using Amazon’s boto3 library in Python. Getting started For those unfamiliar with the Bedrock runtime API, I have a post that…
Using LangChain, we can create a prompt to output a bash, which is then executed via the BashProcess tool. All of this is as easy as a few lines of Python code! How to generate bash scripts using LangChain First, let’s install the necessary dependencies: 1pip install langchain-core langchain-experimental langchain-openaiNow, let’s write a simplistic prompt to get OpenAI to output bash…
Unix provides a utility named date. As its name implies, it allows you to fetch your system’s date. Display the current date Displaying the current date is simple: 1echo $(date)Output: 1Sat Feb 10 21:29:37 EST 2024The system date was printed with the timezone information. Display the current date in UTC Similarly, we can display the current date in UTC (Coordinated Universal Time) using the…
Last year, I wrote a post showcasing how to tokenize words using the Anthropic SDK to track token usage. While this method continues to work, it’s not necessary since the Amazon Bedrock team added token metrics to the SDK response metadata. In this guide, we’ll explore the SDK and how to get those token counts. Install the AWS SDK To begin, install boto3, the AWS SDK for Python, using…
In this article, we’ll go over how to properly test exit codes in Bash scripts. Testing exit codes with $? When I first started writing Bash, I often wrote the following code to test whether a program’s execution was successful: 1some_command 2if [ '$?' -eq 0 ]; then 3 echo 'It worked!' 4fiHowever, this introduces complexity in the flow of the script. For example, one minor mistake…
LangChain is a framework that streamlines developing LLM applications. In a nutshell, it provides abstractions that help build out common steps and flows for working with LLMs. In this post, we’ll go over how to integrate Embedchain, an open source RAG framework, with AWS Bedrock! What is Embedchain Embedchain is an open source RAG framework aimed at allowing developers to quickly gather…
Retrieval-Augmented Generation (RAG) is a technique for including contextual information from external sources in a large language model’s (LLM) prompt. In other terms, RAG is used to supplement an LLM’s answer by providing more information in the prompt; thus, removing the need to retrain or fine-tune a model. For the purposes of this post, we will implement RAG by using Chroma DB as…
AWS introduced a PartiQL in 2019 as a “query language for all your data” that resembles SQL-like expressions. In November 2020, it was natively integrated with DynamoDB. In this post, we’ll explore using PartiQL with DynamoDB. What is PartiQL PartiQL is an open source initiative that is maintained by Amazon under the Apache 2.0 license. Its goal is to be a SQL-compatible query…
Historically in Python, adding explicit typing for kwargs was not directly supported; however, Python 3.12 added that ability. In this post, we’ll go over methods for adding types to the kwargs argument. Adding type annotations to kwargs Python 3.12 released a new method for explicitly typing kwargs: using a TypedDict + Unpack. 1from typing import NotRequired, TypedDict, Unpack 2 3 4class…
Postman used to be my favorite API testing tool, but the company’s decision to phase out the final local collection storage feature, Scratchpad, in favor of mandatory cloud services, has changed that. What is the best Postman alternative? Finding an alternative means it must satisfy the following requirements: Local collection storage Git-friendly collection definitions for my team members…
Tags are key/value metadata that enable users to categorize their AWS infrastructure. This is useful for identifying groups of resources, monitoring cloud spending, creating reports, etc. In this post, we’ll explore different methods for tagging infrastructure using the AWS CDK. The code samples are in Python, but the techniques are applicable to all languages. Tagging constructs Constructs…
Last year, I wrote a post describing the difference between aws cloudformation deploy and aws cloudformation create-stack. I concluded that the easiest method for deploying CloudFormation templates was cloudformation deploy since it handled change sets on your behalf. My opinion has changed; I discovered a new tool named Rain that is maintained by AWS. What is Rain For folks needing to deploy raw…
Amazon DynamoDB is a fully managed service provided by AWS that enables developers to quickly store data for their applications. In this article, I will showcase how to implement version control in DynamoDB for recording changes to data over time. What is version control in DynamoDB DynamoDB does not support native version control on a per-item basis. If you need to record changes to your data…
I need to create an IAM role that is assumable by multiple principals, but the AWS CDK role creation documentation only lists the following example: 1lambda_role = iam.Role(self, 'Role', 2 assumed_by=iam.ServicePrincipal('lambda.amazonaws.com'), 3 description='Example role...' 4) 5 6stream = kinesis.Stream(self, 'MyEncryptedStream', 7 encryption=kinesis.StreamEncryption.KMS 8) 9…
By the end of this article, you’ll have a Python app deployed with FastAPI using AWS Lambda and API Gateway that is serving requests. In addition, you will have the infrastructure defined in code. What is AWS Lambda and API Gateway AWS Lambda and Amazon API Gateway are two services offered by AWS that enable developers to quickly spin up infrastructure without the hassle of provisioning or…
Amazon API Gateway + AWS Lambda is a powerful duo for creating easy-to-deploy scalable infrastructure that is immediately accessible by thousands of users. For this post, we will create an API Gateway with an lambda proxy integration using the AWS Lambda Powertools library and the AWS CDK. In just a few lines of code, we’ll have our API deployed and ready to go! This tutorial assumes you…
For this post, I will extend the AWS documentation for ‘Building a custom runtime’ by additionally using the AWS CDK in Python to deploy the Bash custom runtime for AWS Lambda. How to deploy a Lambda custom runtime using AWS CDK Follow the instructions below to deploy an AWS Lambda Function with a Bash custom runtime! Create a /handler folder with a bootstrap file AWS provides a…
Going into 2024, I wanted to minimize the footprint of how.wtf. This included: Removing ads Removing giscus, the commenting system Removing Google Analytics Reducing the website’s size to less than 20kb Changing the theme to be super minimal with a focus on content I have nothing against Google Analytics; I simply wanted something with less impact on my website’s loading speeds.…
Retrieving the top 10 used commands in Linux is simple using the history command. What is the history command The history command, as its name implies, is used to view previously executed commands. It’s API is minimal and easy to use. How to view top used commands in Linux Using a combination of history and awk, we can pull the top 10 commands like this: 1history | 2 awk…
For a side project, I needed to wait for multiple threads to complete before proceeding with the next step. In other words, I needed threads to behave like the Promise.all() functionality of JavaScript. Wait for threads in Python In the sections below, we’ll discuss different methods for waitin on threads to complete in Python. Wait for all threads to complete using start / join In simple…
Amazon Bedrock is a managed service provided by AWS that allows users to invoke models. For more information about the service, please refer to their user guide here. For this article, we’re going to focus on how to invoke the Stable Diffusion model using the Python SDK: boto3. If you want to learn about the Amazon Bedrock SDK in general or how to invoke Claude with it, I have an article…
AWS released an optimized integration for Amazon Bedrock. It allows StepFunction statemachines to directly call the Amazon Bedrock API without needing to write a Lambda function. How to deploy a StepFunction with Amazon Bedrock integration using AWS CDK Follow the instructions below to deploy a StepFunction with Amazon Bedrock integration using the AWS CDK. The following tutorial uses Python, but…
Amazon Bedrock is a managed service provided by AWS that provides foundational models at your fingertips through a unified API. The service offers a range of features including foundational model invocations, fine-tuning, agents, guardrails, knowledge base searching, and more! To read more about the service offerings, refer to its documentation. What is Amazon Bedrock Runtime? For this article,…
Before typing was released for Python, the ABC class reigned as champion for describing shape and behaviors of classes. After type annotations, ABC and @abstractmethod were still used to describe the behaviors: they felt ‘interface-like’. Then, Protocol was released and introduced a new way for declaring class behaviors. Should you use ABC or Protocol? Before describing why or why not…
Retrieval-Augmented Generation (RAG) is a technique for improving an LLM’s response by including contextual information from external sources. In other terms, it helps a large language model answer a question by providing facts and information for the prompt. For the purposes of this tutorial, we will implement RAG by leveraging a Chroma DB as a vector store with the FDIC Failed Bank List…
After pushing changes to a remote repository, a common next step is creating a pull request for your team members to review. In this article, we’ll discuss how to open a pull request from the command line using the GitHub CLI. What is the GitHub CLI The GitHub CLI is a tool that allows users to interact with GitHub directly from the terminal. It simplifies and streamlines GitHub workflows,…
Amazon DynamoDB’s Time to Live (TTL) feature allows for automatic item deletion after a specified timestamp. It comes at no extra cost and is useful for removing outdated data. TTL use-cases Remove stale data and save on DynamoDB memory usage Retain sensitive data only up to contractual or regulatory obligations Trigger processes using DynamoDB Streams based on TTL deletions since the…
In this article, we’ll discuss how to use NordVPN on Linux. This includes installation, authentication, and general usage of the CLI in Linux. Please note, the links provided for NordVPN are affiliate links. This means if you click on them and make a purchase, I may receive a commission at no extra cost to you. This helps support the blog and allows me to continue creating content like this.
Docker Desktop was my de facto choice on MacOS due to its ease of installation and container management. This changed after Docker updated their subscription service agreement. Step-by-step guide to installing Docker without Docker Desktop The following tutorial assumes that you use brew as your package manager. Install docker Firstly, install docker and docker-credential-helper. 1brew install…
AWS Lambda is an easy-to-use serverless offering that enables developers to quickly deploy code without worrying about maintenance, orchestration, scaling, etc. It’s simple to get started and its free tier is generous! Golang project structure GO does not have a recommended project structure. In fact, keeping a project structure flat is preferrable for small apps: 1project/ 2├── go.mod 3├──…
Tracking Amazon Bedrock Claude token usage is simple using Langchain! How to track tokens using Langchain For OpenAI models, Langchain provides a native Callback handler for tracking token usage as documented here. 1from langchain.callbacks import get_openai_callback 2from langchain.llms import OpenAI 3 4llm = OpenAI(temperature=0) 5with get_openai_callback() as cb: 6 llm('What is the square root…
Monitoring token consumption in Anthropic-based models can be straightforward and hassle-free. In fact, Anthropic offers a simple and effective method for accurately counting tokens using Python! In this guide, I’ll show you how to count tokens for Amazon Bedrock Anthropic models. Installing the Anthropic Bedrock Python Client To begin, install the Amazon Bedrock Python client using pip:…
DALL-E is an OpenAI model that generates images from textual descriptions. It combines elements of creativity and technology to produce unique imagery based on human prompts. Tip 1 - DALL-E Prompt Book To kick things off, I recommend reviewing the DALL-E prompt book released by the dallery gallery. It contains many useful techniques for describing tone, emotion, angles, lightning, illustration…
OpenAI has two products that are similar: Assistants and GPTs. In this article, we’ll discuss the differences between the two. What are OpenAI GPTs? GPTs (custom versions of ChatGPT) are specialized tools designed to cater to specific needs and preferences. They enable users, including those without coding skills, to tailor ChatGPT for distinct tasks or interests. Users can create GPTs for…
In this article, we’ll cover how to easily leverage Amazon Bedrock in Langchain. What is Amazon Bedrock? Amazon Bedrock is a fully managed service that provides an API to invoke LLMs. At the time of writing, Amazon Bedrock supports: Anthropic Claude Meta Llama Cohere Command Stability AI SDXL A121 Labs Jurassic with many more slated to come out! How to use Amazon Bedrock with Langchain…
Hosting large langage models (LLMs) locally is simple using LocalAI. What is LocalAI LocalAI is an open source alternative to OpenAI. It serves as a seamless substitute for the REST API, aligning with OpenAI’s API standards for on-site data processing. With LocalAI, you can effortlessly serve Large Language Models (LLMs), as well as create images and audio on your local or on-premise systems…
Vector databases have seen an increase in popularity due to the rise of Generative AI and Large Language Models (LLMs). Vector databases can be used in tandem with LLMs for Retrieval-augmented generation (RAG) - i.e. a framework for improving the quality of LLM responses by grounding prompts with context from external systems. What is Chroma DB? Chroma is an open-source embedding database that…
What are the differences between Langchain and LlamaIndex and what are their use cases? In this article, we’ll explore these differences, helping you choose the most suitable library for your needs. What is Langchain? As the documentation outlines, LangChain is a framework for developing applications powered by language models. Langchain is a framework that enables developers to build…
Reverting a submodule in Git is simple. How to revert changes to a Git submodule The cleanest / easiest method of reverting changes to one or many git submodules is by using the following two commands: 1git submodule deinit -f . 2git submodule update --initThe git submodule deinit -f . command “deinitializes” all submodules in the repository. The git submodule update --init command…
Deploying Lambda Function URLs with the AWS CDK is simple. How to deploy Function URLs using AWS Python CDK Follow the instructions below to deploy an AWS Lambda Function with a URL. Create a requirements.txt For this tutorial, version 2.106.1 of the AWS CDK was used. 1aws-cdk-lib==2.106.1 2constructs>=10.0.0,<11.0.0Install the dependencies 1pip3 install -r requirements.txtCreate /handler folder…
Implementing custom memory in Langchain is dead simple using the ChatMessageHistory class. How to implement custom memory in Langchain (including LCEL) One of the easiest methods for storing and retrieving messages with Langchain is using the ChatMessageHistory class that is provided from the langchain.memory module. It’s simple to get started with: 1from langchain.memory import…
Learn the simple process of iterating through a JSON array in bash with the help of jq. Iterate through a JSON array using jq Scenario: You have a file named projects.json contains an array named “projects” that you want to iterate through. 1{ 2 'projects': [ 3 { 4 'name': 'project 1', 5 'owner': 'owner 1', 6 'id': 1, 7 'version': '2.3.0' 8 }, 9 { 10 'name': 'project 2', 11 'owner':…