AWS

Testing Blog Automation System

By CloudNestle Team•2/16/2026
TestingAutomation

Testing Blog Automation System

Introduction

Welcome to our technical blog post designed to demonstrate the complete workflow of an automated blog generation and publishing system. This system leverages Amazon Bedrock for content generation, DynamoDB for storage, and the GitHub API for publishing. This post will walk you through each step of the process, providing practical examples and code snippets to help you implement a similar system in your organization.

System Overview

The automated blog generation and publishing system consists of the following components:

  1. Amazon Bedrock: Used for generating blog content.
  2. DynamoDB: Stores blog metadata and content.
  3. GitHub API: Handles the publishing of blog posts to a live website.

Use Case

Imagine you are part of a team that needs to regularly publish technical blog posts to keep your audience engaged. Manually writing and publishing these posts can be time-consuming. By automating the process, you can focus more on strategic tasks while ensuring a consistent flow of content.

Step 1: Content Generation with Amazon Bedrock

Amazon Bedrock is a powerful service that can generate high-quality content based on provided prompts. For this example, we will use Bedrock to generate a technical blog post about AWS best practices.

Example Prompt

Generate a 1000-word technical blog post about AWS best practices for cost optimization.

Bedrock API Call

Here’s an example of how you might call the Bedrock API to generate content:

import boto3

bedrock = boto3.client('bedrock')

response = bedrock.generate_content(
    prompt="Generate a 1000-word technical blog post about AWS best practices for cost optimization."
)

generated_content = response['content']

Step 2: Storing Blog Metadata in DynamoDB

Once the content is generated, we need to store it along with its metadata in DynamoDB. This allows us to keep track of all blog posts and their details.

DynamoDB Table Structure

Our DynamoDB table, BlogPosts, will have the following structure:

  • PostID (Primary Key): Unique identifier for each blog post.
  • Title: Title of the blog post.
  • Content: The generated blog content.
  • Author: Author of the blog post.
  • PublishDate: Date the post was published.

Example DynamoDB Put Item

Here’s how you can store the generated content in DynamoDB:

import boto3

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('BlogPosts')

post_id = "POST#001"
title = "AWS Best Practices for Cost Optimization"
author = "John Doe"
publish_date = "2023-10-01"

table.put_item(
    Item={
        'PostID': post_id,
        'Title': title,
        'Content': generated_content,
        'Author': author,
        'PublishDate': publish_date
    }
)

Step 3: Publishing to GitHub

With the content stored in DynamoDB, the next step is to publish it to a live website hosted on GitHub Pages. We’ll use the GitHub API to create a new file in the repository containing the blog post.

GitHub API Authentication

First, you need to authenticate with the GitHub API. You can use a Personal Access Token (PAT) for this purpose.

Example GitHub API Call

Here’s how you can create a new Markdown file in your GitHub repository:

import requests
import base64

repo_owner = "your-username"
repo_name = "your-repo"
branch = "main"
path = "_posts/2023-10-01-aws-best-practices-for-cost-optimization.md"
message = "Add new blog post"
content = f"---\ntitle: \"{title}\"\nauthor: \"{author}\"\ndate: {publish_date}\n---\n\n{generated_content}"

github_token = "your-github-token"
headers = {
    "Authorization": f"token {github_token}",
    "Accept": "application/vnd.github.v3+json"
}

url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/contents/{path}"

response = requests.put(url, headers=headers, json={
    "message": message,
    "content": base64.b64encode(content.encode()).decode(),
    "branch": branch
})

if response.status_code == 201:
    print("Blog post published successfully!")
else:
    print(f"Failed to publish blog post: {response.json()}")

Step 4: Automated Workflow

To fully automate this process, you can set up an AWS Lambda function that triggers whenever a new item is added to the DynamoDB table. The Lambda function will handle the content generation, storage, and publishing steps.

Example Lambda Function

Here’s a simplified version of what the Lambda function might look like:

import boto3
import requests
import base64

bedrock = boto3.client('bedrock')
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('BlogPosts')

def lambda_handler(event, context):
    for record in event['Records']:
        if record['EventName'] == 'INSERT':
            new_post = record['DynamoDB']['NewImage']
            
            post_id = new_post['PostID']['S']
            title = new_post['Title']['S']
            author = new_post['Author']['S']
            publish_date = new_post['PublishDate']['S']
            
            # Generate content
            response = bedrock.generate_content(
                prompt=f"Generate a 1000-word technical blog post about {title}."
            )
            generated_content = response['content']
            
            # Store in DynamoDB
            table.put_item(
                Item={
                    'PostID': post_id,
                    'Title': title,
                    'Content': generated_content,
                    'Author': author,
                    'PublishDate': publish_date
                }
            )
            
            # Publish to GitHub
            repo_owner = "your-username"
            repo_name = "your-repo"
            branch = "main"
            path = f"_posts/{publish_date.replace('-', '')}-{title.lower().replace(' ', '-')}.md"
            message = "Add new blog post"
            content = f"---\ntitle: \"{title}\"\nauthor: \"{author}\"\ndate: {publish_date}\n---\n\n{generated_content}"
            
            github_token = "your-github-token"
            headers = {
                "Authorization": f"token {github_token}",
                "Accept": "application/vnd.github.v3+json"
            }
            
            url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/contents/{path}"
            
            response = requests.put(url, headers=headers, json={
                "message": message,
                "content": base64.b64encode(content.encode()).decode(),
                "branch": branch
            })
            
            if response.status_code == 201:
                print("Blog post published successfully!")
            else:
                print(f"Failed to publish blog post: {response.json()}")

    return {
       'statusCode': 200,
        'body': 'Blog post processed successfully'
    }

Conclusion

In this blog post, we’ve walked through the complete workflow of an automated blog generation and publishing system using Amazon Bedrock, DynamoDB, and the GitHub API. By following these steps, you can create a robust system that generates, stores, and publishes blog posts with minimal manual intervention.

This system not only saves time but also ensures a consistent flow of high-quality content for your audience. Whether you’re looking to keep your technical blog updated or need a way to automate content generation for your team, this approach provides a scalable and efficient solution.

Happy blogging!

šŸ’”

Need Expert Help?

Our AWS certified professionals can help you implement these strategies in your organization.