首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >serverless.yml中Lambda@Edge的无服务器函数ARN

serverless.yml中Lambda@Edge的无服务器函数ARN
EN

Stack Overflow用户
提问于 2018-10-25 08:11:59
回答 1查看 1K关注 0票数 1

我正在尝试弄清楚是否有可能在CloudFront发行版上为Lambda@Edge在同一文件中使用在serverless.yml文件中定义的Lambda函数的ARN。

我的代码在下面,就在底部,我想指定我在同一个无服务器文件中定义的Lambda函数的ARN。

提前谢谢。

代码语言:javascript
运行
复制
functions:

    myLambdaFunction:
        handler: handler.myLambdaFunction

resources:
    Resources:

        WebsiteS3Bucket:
            Type: AWS::S3::Bucket
            Properties: 
                BucketName: website-bucket
                WebsiteConfiguration:
                    ErrorDocument: index.html
                    IndexDocument: index.html

        WebsiteCloudFrontOriginAccessIdentity:
            Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
            Properties:
                CloudFrontOriginAccessIdentityConfig:
                    Comment: website-bucket-cloudfront-origin-access-identity

        WebsiteS3BucketPolicy:
            Type: AWS::S3::BucketPolicy
            Properties: 
                Bucket: 
                    Ref: WebsiteS3Bucket
                PolicyDocument: 
                    Statement: 
                        - 
                            Action: 
                                - "s3:GetObject"
                                - "s3:ListBucket"
                            Effect: "Allow"
                            Resource: 
                                - Fn::Join: 
                                    - ""
                                    - 
                                        - Fn::GetAtt: [ WebsiteS3Bucket, Arn ]
                                        - "/*"
                                - Fn::Join: 
                                    - ""
                                    - 
                                        - Fn::GetAtt: [ WebsiteS3Bucket, Arn ]
                            Principal:
                                AWS:
                                    Fn::Join:
                                        - ""
                                        -
                                            - "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity "
                                            - Ref: WebsiteCloudFrontOriginAccessIdentity

        WebsiteCloudFront:
            Type: AWS::CloudFront::Distribution
            Properties:
                DistributionConfig: 
                    Enabled: true
                    Origins:
                        -
                            DomainName:
                                Fn::Join:
                                    - ""
                                    -
                                        - Ref: WebsiteS3Bucket
                                        - ".s3.amazonaws.com"
                            Id:
                                Ref: WebsiteS3Bucket
                            S3OriginConfig:
                                OriginAccessIdentity:
                                    Fn::Join:
                                        - ""
                                        -
                                            - "origin-access-identity/cloudfront/"
                                            - Ref: WebsiteCloudFrontOriginAccessIdentity
                    CustomErrorResponses:
                        -
                            ErrorCode: 404
                            ResponseCode: 200
                            ResponsePagePath: /index.html
                    DefaultRootObject: /index.html
                    DefaultCacheBehavior:
                        ForwardedValues:
                            QueryString: true
                        TargetOriginId:
                            Ref: WebsiteS3Bucket
                        ViewerProtocolPolicy: redirect-to-https
                        LambdaFunctionAssociations:
                            -
                                EventType: origin-response
                                LambdaFunctionARN: ## Lambda function ARN here
EN

回答 1

Stack Overflow用户

发布于 2018-10-25 11:42:32

代码语言:javascript
运行
复制
Ref: myLambdaFunction

看起来您已经在模板中引用了Ref。这里引用的是当您在Lambda函数上使用Ref时的值:

Ref Documentation

我通常通过以下方式引用它们:

代码语言:javascript
运行
复制
!GetAtt [LambdaResourceName, Arn]
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52979583

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档