【发布时间】:2021-01-05 14:48:58
【问题描述】:
我的团队正在使用 Azure Devops 管道将 Cloudformation 堆栈部署到 AWS。我们有可重用的通用 Cloudformation 模板(例如,可重用于部署多个 Lambda 函数的单个 Lambda.yml Cloudformation 模板)。
除此之外,我还设置了一个阶梯函数来编排逻辑流程。 step 函数步骤需要引用基础架构各个部分的 ARN(对于本示例,重点关注 lambda 函数)。
由于 Lambda.yml 被重用,每次任务重用模板来部署新的 lambda 时,输出变量都会被覆盖。我想在 Azure Devops 的变量或参数中捕获每个任务之后的输出。我查看了许多示例和有关变量的文档,但我无法让它工作。 Cloudformation 模板和部署脚本的相关部分在此处列出(YAML 格式)。
Lambda.yml(Cloudformation 模板)
AWSTemplateFormatVersion: '2010-09-09'
Description: Template for Lambda function.
Parameters:
FunctionName:
Description: The name of the Lambda function
Type: String
Resources:
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Ref FunctionName
.....
Outputs:
LambdaFunctionName:
Description: Lambda function name
Value: !Ref LambdaFunction
LambdaFunctionARN:
Description: Lambda ARN
Value:
Fn::GetAtt:
- LambdaFunction
- Arn
Deploy.yml(Azure Devops 管道部署)
# Deploy.yml is a series of deployment tasks called from a job/stage defined in another.yml file
# LambdaFunctionNumber1
- task: AmazonWebServices.aws-vsts-tools.CloudFormationCreateOrUpdateStack.CloudFormationCreateOrUpdateStack@1
displayName: 'Stack: LambdaFunctionNumber1'
inputs:
templateSource: s3
s3BucketName: ${{ parameters.azdoS3ArtifactBucket }}
s3ObjectKey: '${{ parameters.azdoS3ArtifactPrefix }}/cfn/Lambda.yml'
templateParametersSource: inline
templateParameters: |
-
ParameterKey: FunctionName
ParameterValue: LambdaFunctionNumber1
....
captureStackOutputs: asVariables
# I would like to capture Cloudformation output variables here for use in other tasks
# variables lambdaNumberOneFunctionName and lambdaNumberOneFunctionArn are defined as variables by the job triggering these deployment tasks, and initialized to empty strings
- bash:
echo "##vso[task.setvariable variable=lambdaNumbertOneFunctionName;isOutput=true]$LAMBDAFUNCTIONNAME"
echo "##vso[task.setvariable variable=lambdaNumberOneFunctionArn;isOutput=true]$LAMBDAFUNCTIONARN"
# LambdaFunctionNumber2
- task: AmazonWebServices.aws-vsts-tools.CloudFormationCreateOrUpdateStack.CloudFormationCreateOrUpdateStack@1
displayName: 'Stack: LambdaFunctionNumber2'
inputs:
templateSource: s3
s3BucketName: ${{ parameters.azdoS3ArtifactBucket }}
s3ObjectKey: '${{ parameters.azdoS3ArtifactPrefix }}/cfn/Lambda.yml'
templateParametersSource: inline
templateParameters: |
-
ParameterKey: FunctionName
ParameterValue: LambdaFunctionNumber2
....
captureStackOutputs: asVariables
# At this point the $(LambdaFunctionARN) output variable is set from Cloudformation of LambdaFunctionNumber2.
# The ARN from LambdaFunctionNumber1 is lost unless I capture it somehow.
# I need multiple ARNs to provide as input to the Step Function that gets deployed here
- task: AmazonWebServices.aws-vsts-tools.CloudFormationCreateOrUpdateStack.CloudFormationCreateOrUpdateStack@1
displayName: 'Stack: Step Function'
inputs:
stackName:step-function
templateSource: s3
s3BucketName: ${{ parameters.azdoS3ArtifactBucket }}
s3ObjectKey: '${{ parameters.azdoS3ArtifactPrefix }}/cfn/StepFunction.yml'
....
templateParametersSource: inline
templateParameters: |
-
ParameterKey: StateMachineName
ParameterValue: orchestration-step-function
-
# This doesn't work
ParameterKey: State1LambdaArn
ParameterValue: $[lambdaNumberOneFunctionArn]
-
# This works but only allows capturing the most recent output variable
ParameterKey: State2LambdaArn
ParameterValue: $(LambdaFunctionARN)
【问题讨论】:
-
没有得到您的最新信息,Krzysztof Madej 的回答对您有帮助吗?或者,如果您有任何疑虑,请随时在此处分享。
标签: azure-devops continuous-integration amazon-cloudformation azure-pipelines continuous-deployment