【问题标题】:AWS CloudFormation - Adding parameter (keypair) to json from Azure DevOpsAWS CloudFormation - 从 Azure DevOps 向 json 添加参数(密钥对)
【发布时间】:2022-01-12 11:53:11
【问题描述】:

AWS 上有一个 VPC Basic cloudformation 模板可用。这是代码的链接:https://s3.us-west-2.amazonaws.com/cloudformation-templates-us-west-2/VPC_Single_Instance_In_Subnet.template

当我使用 CloudFormation 创建它时,它会失败,除非我使用 GUI 指定密钥对。当我指定密钥对时,它可以工作。

问题是,我正在尝试使用 AWS 的集成工具包从 AzureDevOps 运行此 cloudformation 模板。

目前,我这样做的方式是,我只是传递一个指向模板文件的链接。模板文件包含 JSON 格式的模板,但我不确定:

a) 我应该在上面链接的模板文件中插入密钥对名称

b) 其他方式?

我正在为 Azure DevOps 使用 AWS 工具包

这是我的代码:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
pool:
  vmImage: ubuntu-latest
steps:
- task: CloudFormationCreateOrUpdateStack
  inputs:
    awsCredentials: 'aws_test'
    regionName: 'us-west-2'
    stackName: 'test'
    templateSource: 'url'
    templateUrl: 'https://s3.us-west-2.amazonaws.com/cloudformation-templates-us-west-2/VPC_Single_Instance_In_Subnet.template'
- script: echo Hello, world!
  displayName: 'Run a one-line script'
- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'

我在运行时遇到的错误是参数KeyPair需要一个值。

【问题讨论】:

    标签: amazon-web-services azure amazon-cloudformation devops


    【解决方案1】:

    如果您有想要使用的预定义键,您可以设置一个默认值

        "KeyName": {
          "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
          "Type": "AWS::EC2::KeyPair::KeyName",
          "Default": "your-key-pari-name",
          "ConstraintDescription" : "must be the name of an existing EC2 KeyPair."
        },
    

    这样您就不必显式设置它的值,除非它与默认值不同。

    【讨论】:

    • 知道了,谢谢!我将尝试将默认参数添加到 JSON 文件。想知道是否有办法将它添加到上面的管道代码而不是 json 文件中
    • @dislikes_dishwashing 不确定您的意思。您可以在CloudFormationCreateOrUpdateStack 中指定templateParameters
    • 感谢队友解决
    猜你喜欢
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 2019-12-01
    • 1970-01-01
    相关资源
    最近更新 更多