Skip to content

Using S3 with Other AWS Services

This guide provides an overview of how Amazon S3 can be integrated with other AWS services to build powerful and scalable applications. S3 is a foundational service in AWS, and many other services are designed to work with it seamlessly.

Before you begin, you will need:

  • An active University of Oregon AWS account.
  • An existing S3 bucket. You can create one by following our Using Amazon S3 for Object Storage guide.
  • A basic understanding of other AWS services, such as EC2, Lambda, and CloudFront.

Here are some of the most common ways to use S3 with other AWS services:

You can use S3 to store data that needs to be accessed by your EC2 instances. For example, you can store application code, images, or other assets in S3 and then download them to your EC2 instances when they are launched. This is a common pattern for building scalable and resilient applications.

S3 can be used as an event source for Lambda functions. This means that you can trigger a Lambda function to run automatically whenever a new object is created in your S3 bucket. This is a powerful way to build event-driven applications, such as image processing pipelines or data analysis workflows.

You can use S3 as the origin for a CloudFront distribution. This allows you to serve your content from S3 through CloudFront’s global network of edge locations, which can significantly improve the performance and latency of your website or application.

CloudTrail is a service that records all API calls made to your AWS account. You can configure CloudTrail to store its log files in an S3 bucket, which can be useful for security auditing and compliance.

The following Terraform code will create an S3 bucket and a Lambda function that is triggered whenever a new object is created in the bucket.

# main.tf - Example for creating an S3 bucket and a Lambda function
resource "aws_s3_bucket" "image_storage" {
bucket = "uo-myapp-image-bucket" # Please use a long, unique name
tags = {
Name = "UO Myapp Image Bucket"
Environment = "Production"
}
}
resource "aws_iam_role" "lambda_role" {
name = "lambda_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "lambda.amazonaws.com"
}
},
]
})
}
resource "aws_lambda_function" "image_processor" {
function_name = "image_processor"
role = aws_iam_role.lambda_role.arn
handler = "index.handler"
runtime = "nodejs16.x"
filename = "lambda_function.zip"
source_code_hash = filebase64sha256("lambda_function.zip")
}
resource "aws_s3_bucket_notification" "bucket_notification" {
bucket = aws_s3_bucket.image_storage.id
lambda_function {
lambda_function_arn = aws_lambda_function.image_processor.arn
events = ["s3:ObjectCreated:*"]
}
}
  • resource "aws_s3_bucket" "image_storage": This block declares a new S3 bucket resource.
  • resource "aws_iam_role" "lambda_role": This block creates an IAM role that the Lambda function will assume when it is executed.
  • resource "aws_lambda_function" "image_processor": This block creates a new Lambda function. You will need to provide the deployment package (lambda_function.zip) for your function.
  • resource "aws_s3_bucket_notification" "bucket_notification": This block creates a notification on the S3 bucket that will trigger the Lambda function whenever a new object is created.

Now that you have a basic understanding of how to use S3 with other AWS services, you can start building more complex and powerful applications.