gpt4 book ai didi

aws-lambda - 放大获取 lambda 中的托管 URL 作为环境变量

转载 作者:行者123 更新时间:2023-12-04 10:55:09 30 4
gpt4 key购买 nike

我需要使用 amplify cli 添加的 Cloudfront 发行版的 URL 作为环境变量。
地位:
enter image description here

我发现如何在我的函数配置下的文件“api-cloudformation-template.json”中添加模板变量。
来自“hosting/S3AndCloudFront/template.json”的期望输出变量是 CloudFrontSecureURL .
所以我在 lambda 配置文件中添加了行,如下所示:

 {
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Lambda resource stack creation using Amplify CLI",
"Parameters": {
...
"hostingS3AndCloudFrontHostingBucketName": { // working example
"Type": "String",
"Default": "hostingS3AndCloudFrontHostingBucketName"
},
"hostingS3AndCloudFrontCloudFrontSecureURL": { // my example
"Type": "String",
"Default": "hostingS3AndCloudFrontCloudFrontSecureURL"
},
},
"Resources": {
"LambdaFunction": {
"Type": "AWS::Lambda::Function",
"Metadata": {
"aws:asset:path": "./src",
"aws:asset:property": "Code"
},
"Properties": {
...
"Environment": {
"Variables": {
...
"HOSTING_S3ANDCLOUDFRONT_HOSTINGBUCKETNAME": {
"Ref": "hostingS3AndCloudFrontHostingBucketName"
},
"HOSTING_S3ANDCLOUDFRONT_CLOUDFRONTSECUREURL": {
"Ref": "hostingS3AndCloudFrontCloudFrontSecureURL"
}
}
},

}
}
....
},
....
}

我收到 hostingS3AndCloudFrontCloudFrontSecureURL (默认值)在 process.env.HOSTING_S3ANDCLOUDFRONT_CLOUDFRONTSECUREURL发布功能后。

最佳答案

尝试使用 Outputs模板部分以及 Fn::ImportValue 函数文档 HERE

CloudFront 堆栈:

{
...
"Outputs" : {
"CloudfrontDomainOutput" : {
"Description" : "The cloudfront domain",
"Value" : {
"Fn::GetAtt": [
"hostingS3AndCloudFrontCloudFrontSecureURL",
"DomainName"
]
},
"Export" : {
"Name" : {"Fn::Sub": "${AWS::StackName}-hostingS3AndCloudFrontCloudFrontSecureURL" }
}
}
}


Lambda 堆栈


{
...
"Environment": {
"Variables": {
"HOSTING_S3ANDCLOUDFRONT_HOSTINGBUCKETNAME": {
"Ref": "hostingS3AndCloudFrontHostingBucketName"
},
"HOSTING_S3ANDCLOUDFRONT_CLOUDFRONTSECUREURL": {
"Fn::ImportValue" : {"Fn::Sub" : "${CloudFront_Stack_Name}-hostingS3AndCloudFrontCloudFrontSecureURL"}
}
}
}
}

关于aws-lambda - 放大获取 lambda 中的托管 URL 作为环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59253324/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com