AWS CloudFormation - 从 Azure DevOps 添加参数(密钥对)到 json

AWS CloudFormation - Adding parameter (keypair) to json from Azure DevOps

AWS 上提供了一个 VPC Basic cloudformation 模板。这是代码的 link:https://s3.us-west-2.amazonaws.com/cloudformation-templates-us-west-2/VPC_Single_Instance_In_Subnet.template

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

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

目前,我这样做的方式是,我只是将 link 传递给模板文件。模板文件包含JSON中的模板,但我不确定:

a) 我应该将密钥对名称插入上面的模板文件 linked

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 需要一个值。

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

    "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."
    },

这样你就不必明确设置它的值,除非它与默认值不同。