AIショートドラマ広告の現在地
Trend Analysis 2026 AIショートドラマ広告の現在地 —— ...
Z. Xingjie
2026年05月11日
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.
Trend Analysis 2026 AIショートドラマ広告の現在地 —— ...
Z. Xingjie
2026年05月11日
Have you ever tried to push code to your personal GitHub repository, only to be met with a frustrating error like this? ERROR: Permission to person...
Iftekhar Eather
2026年04月08日
AI FOMOを乗り越える —— 新技術の追求から課題解決への転換 ...
Z. Xingjie
2026年04月02日