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

Time:01-13

There's a VPC Basic cloudformation template available on AWS. Here's the link to the code: https://s3.us-west-2.amazonaws.com/cloudformation-templates-us-west-2/VPC_Single_Instance_In_Subnet.template

When I create it using CloudFormation, it fails unless I specify a keypair using the GUI. When I specify the keypair, it works.

Issue is, I am trying to run this cloudformation template from AzureDevOps using the integration toolkit by AWS.

At the moment, the way I do this is, I'm just passing a link to a template file. The template file contains the template in JSON, but I'm not sure if:

a) I'm supposed to insert the keypair name in the template file linked above

OR

b) some other way?

I'm using the AWS toolkit for Azure DevOps

This is my code:

# 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'

The error I get when running it is that the parameter KeyPair needs a value.

CodePudding user response:

You can set a default value if you have pre-defined key that you want to use:

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

This way you don't have to explicitly set its value, unless its different from the default one.

  •  Tags:  
  • Related