我需要使用 amplify cli 添加的 Cloudfront 分发 URL 作为环境变量。地位:
我发现如何在我的函数配置下的文件“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