我正在关联AWS Cloudfront中的lambda函数。在关联cloudfront的Web分发的行为模式中的函数时,我得到以下错误:
com.amazonaws.services.cloudfront.model.InvalidLambdaFunctionAssociationException: The function has an invalid runtime for functions that are triggered by a CloudFront event: python2.7 Expecting: nodejs6.10 Function: arn:aws:lambda:us-east-1:316211033416:function:domain_redirects:1 (Service: AmazonCloudFront; Status Code: 400; Error Code: InvalidLambdaFunctionAssociation; Request ID: 8771bb2b-3b50-11e8-a02b-47ca03858fe8)
python lambda函数:
from __future__ import print_function
import json
print('Loading function')
def domain_redirects(event, context):
#print("Received event: " + json.dumps(event, indent=2))
request=event['Records'][0]['cf']['request']
headers=request['headers']
mob_device=["android","iphone","googlebot-mobile"]
user_agent=headers['user-agent'][0]['value'].lower()
for device in mob_device:
if device in user_agent:
response = {
'status':'302',
'statusDescription':'Found',
'headers': {
'location': [
{
'key': 'Location',
'value': 'http://m.bakewish.in'
}
],
}
}
# print (device + "detected")
return response
创建lambda函数的角色具有以下信任关系:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
及以下权限:
1)AWSLambdaEdgeExecutionRole 2)CloudfrontFullAccess
任何帮助表示赞赏!!
答案 0 :(得分:1)
查看documentation看起来你必须使用nodejs6.10运行时来使用cloudfront来处理cloudda。
您必须使用nodejs6.10运行时属性创建函数。