serverless deploy --stage=prod
IAM is available after deploying the lambda function
Add this role under the Trust Relationship tab in IAM (do not add it under the Permissions tab). At the Role aws-redirect-301-prod-us-east-1-lambdaRole
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
add the lambda in behavior tab of the desired distribution
then goto Lambda Function Associations
add CloudFront Event - viewer request - and arn with a version number and do not include body
example arn: arn:aws:lambda:us-east-1:</your-aws-arn-id/>:function:aws-redirect-301-prod-index:<version(1/2/3...)>
edgelambda region must be us-east-1
origin must be the rediricting bucket url
example: s3://</origin-bucket/>.s3-website.</bucket-region/>.amazonaws.com