AI時代のWebサイト生存戦略(六):Webに生成AIを導入
AI時代のWebサイト生存戦略シリーズの第6弾。市場で注目される3つの主要アプローチを詳しく解説し、Web制作企業が高度なカスタマイズ要求に応える直接API導入の可能性についてご紹介します。
Z. Xingjie
2025年10月08日
Implement Basic Auth using lambda function for S3 Website Hosting
To implement basic authentication in AWS CloudFront using a Lambda@Edge function written in Python, follow these steps:
Here’s a step-by-step guide to achieve this:
import base64
def lambda_handler(event, context):
# Get the request object
request = event['Records'][0]['cf']['request']
# Get the headers
headers = request['headers']
# Define the username and password
USERNAME = 'your_username'
PASSWORD = 'your_password'
# Encode the username and password
auth_string = f"{USERNAME}:{PASSWORD}"
encoded_auth_string = base64.b64encode(auth_string.encode()).decode()
# Check for Authorization header
if 'authorization' in headers:
auth_header = headers['authorization'][0]['value']
# Check if the Authorization header matches the encoded auth string
if auth_header == f"Basic {encoded_auth_string}":
return request
# If no valid Authorization header is present, return a 401 Unauthorized response
return {
'status': '401',
'statusDescription': 'Unauthorized',
'headers': {
'www-authenticate': [{'key': 'WWW-Authenticate', 'value': 'Basic'}],
'content-type': [{'key': 'Content-Type', 'value': 'text/html'}]
},
'body': '<html><body><h1>Unauthorized</h1></body></html>'
}
This setup will check for basic authentication on each viewer request. If the credentials are correct, the request will proceed to CloudFront. If not, it will return a 401 Unauthorized response.
======= If you get the following type Error , then follow next steps ========
To update the IAM role to include the necessary permissions for edgelambda.amazonaws.com and lambda.amazonaws.com principals, you need to adjust the trust relationship of the IAM role. Here are the steps to do this:
You need to ensure the trust relationship includes both edgelambda.amazonaws.com and lambda.amazonaws.com. Here is the updated trust relationship policy document:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
},
{
"Effect": "Allow",
"Principal": {
"Service": "edgelambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
{
Replace the existing trust relationship policy document with the above JSON and click “Update Trust Policy”.
Make sure the IAM role has the necessary permissions to execute the Lambda function. Attach the AWSLambdaBasicExecutionRole policy if it’s not already attached.
Once the trust relationship is updated and the necessary permissions are attached, you can retry deploying the Lambda@Edge function to your CloudFront distribution.
AI時代のWebサイト生存戦略シリーズの第6弾。市場で注目される3つの主要アプローチを詳しく解説し、Web制作企業が高度なカスタマイズ要求に応える直接API導入の可能性についてご紹介します。
Z. Xingjie
2025年10月08日
今回のブログでは、Motion Graphics(モーショングラフィックス)の制作について紹介させていただきます。
C. VITHVATCHUTIKUL
2025年08月05日
海外向けのプロモーション動画は、文化や言語の違いを乗り越える必要があるため、ターゲット市場に合わせた戦略的な企画が求められます。 本記事では、海外向けプロモーション動画を作成する際に重要な「企画」の役割に焦点を当て、その成功を引き出すための主要なポイントを解説していきます。
K. Wozniak
2025年06月27日