如何将IAM权限添加到CloudFront以与Lambda@Edge相关联?
我正在尝试使用CDK更新我的CloudFront发行版。在更新时,它提到了此错误消息。
Lambda@Edge cannot retrieve the specified Lambda function. Update the IAM policy to add permission: lambda:GetFunction for resource: arn:aws:lambda:us-east-1:xxxxxxxx:function:edge-lambda-stack-xxxxxxx-xxxxxxxx-xxxxxxx:1
但是,我无法理解在哪里添加这些权限的地方,有人可以指导我在哪里添加lambda:get ferunction:get ferfircrient。
CDK代码
const uriRedirector = new cloudfront.experimental.EdgeFunction(
this,
'UriRedirector',
{
code: lambda.Code.fromAsset('dist/events/object-cache/uri-redirector'),
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handle',
}
)
this.distribution = new cloudfront.Distribution(this, 'Distribution2', {
defaultBehavior: {
origin: s3Origin,
edgeLambdas: [
{
functionVersion: uriRedirector.currentVersion,
eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
},
],
originRequestPolicy: defaultBehaviourOriginRequestPolicy,
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.HTTPS_ONLY,
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
},
....
enter code here
const cfnDistribution = this.distribution.node
.defaultChild as cloudfront.CfnDistribution
cfnDistribution.overrideLogicalId(props.oldDistributionLogicalId)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误是误导的。尽管它说lambda@edge需要
lambda:getFunction
权限,但实际上是创建(或更新)的用户或角色需要此功能和更多权限。您可以在部分所需的IAM noreferrer“> IAM权限。iam:createServiceLinkedrole
用于创建服务角色一次,我通常不包括它。另请注意,所有
lambda:...
权限应具有lambda函数版本ARN,例如arn:aws:aws:lambda:us-east-1:123456789012:功能:函数:my-unction:my-unction: 2
,这是非常不便的。功能ARNARN:AWS:LAMBDA:US-EAST-1:123456789012:功能:my-unction
无法正常工作。幸运的是,您可以用 *替换版本,例如arn:aws:lambda:us-east-1:123456789012:函数:我的功能: *
您的用户或角色策略应具有以下语句:
The error is misleading. Though it says that Lambda@Edge needs
lambda:GetFunction
permission, it's really the user or role that creates (or updates) a CloudFront distribution that needs this and a few more permissions. You can find all the permissions needed in IAM permissions required to associate Lambda@Edge functions with CloudFront distributions section.iam:CreateServiceLinkedRole
is used to create a service role only once, I usually don't include it.Also note, that all
lambda:...
permissions should have a lambda function version ARN, likearn:aws:lambda:us-east-1:123456789012:function:my-function:2
, which is very inconvenient. Function ARNarn:aws:lambda:us-east-1:123456789012:function:my-function
won't work. Fortunately, you can replace the version with *, likearn:aws:lambda:us-east-1:123456789012:function:my-function:*
Your user or role policy should have statements like the following:
您将在IAM中创建IAM策略,并将策略附加到用户或角色
默认情况下,AWS lambda自动创建角色,您可以将策略附加到角色
策略
You will create IAM policy in IAM and attach policy to user or role
By default AWS Lambda automatically create role you can attach policy to role
Policy