Install java11 on windows instance using Cloudformation

I am trying to install jdk11 on ec2 windows instance using cloudformation stack but I am unable to do so. Other packages are being installed and working fine but java 11 is not working. I have tried using choco as well but it is still not working, any help would be appreciated. Its downloading the package but not installing it. It gives an error saying package is broken. This is my cloudformation stack:

---
AWSTemplateFormatVersion: '2010-09-09'
Description: This template installs the required packages on ec2 windows instance
Parameters:
  KeyName:
    Description: Name of an existing EC2 KeyPair
    Type: AWS::EC2::KeyPair::KeyName
    ConstraintDescription: must be the name of an existing EC2 KeyPair.
  InstanceType:
    Description: Amazon EC2 instance type
    Type: String
    Default: t2.medium
    AllowedValues:
    - t2.small
    - t2.medium
    ConstraintDescription: must be a valid EC2 instance type.
  SourceCidrForRDP:
    Description: IP Cidr from which you are likely to RDP into the instances. You
      can add rules later by modifying the created security groups e.g. 54.32.98.160/32
    Type: String
    MinLength: '9'
    MaxLength: '18'
    AllowedPattern: "^([0-9]+.){3}[0-9]+/[0-9]+$"
Mappings:
  AWSRegion2AMI:
    us-east-2:
      Windows2008r2: ami-038739908c6a12458
      Windows2012r2: ami-0b35ce9c4d7659618
Resources:
  SharePointFoundationSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Enable HTTP and RDP
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: '80'
        ToPort: '80'
        CidrIp: 0.0.0.0/0
      - IpProtocol: tcp
        FromPort: '3389'
        ToPort: '3389'
        CidrIp:
          Ref: SourceCidrForRDP
  SharePointFoundationEIP:
    Type: AWS::EC2::EIP
    Properties:
      InstanceId:
        Ref: SharePointFoundation
  SharePointFoundation:
    Type: AWS::EC2::Instance
    Metadata:
      AWS::CloudFormation::Init:
        config:
          files:
            c:cfncfn-hup.conf:
              content:
                Fn::Join:
                - ''
                - - "[main]n"
                  - stack=
                  - Ref: AWS::StackId
                  - "n"
                  - region=
                  - Ref: AWS::Region
                  - "n"
            c:cfnhooks.dcfn-auto-reloader.conf:
              content:
                Fn::Join:
                - ''
                - - "[cfn-auto-reloader-hook]n"
                  - 'triggers=post.update'
                  - 'path=Resources.SharePointFoundation.Metadata.AWS::CloudFormation::Init'
                  - 'action=cfn-init.exe -v -s '
                  - Ref: AWS::StackId
                  - " -r SharePointFoundation"
                  - " --region "
                  - Ref: AWS::Region
                  - "n"
            C:DownloadspackagesGit-2.31.1-64-bit.exe:
              source: https://github.com/git-for-windows/git/releases/download/v2.31.1.windows.1/Git-2.31.1-64-bit.exe
            C:Downloadspackageswix311.exe:
              source: https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311.exe
            C:Downloadspackagesjdk-11.0.11_windows-x64_bin.exe:
              source: https://www.oracle.com/webapps/redirect/signon?nexturl=https://download.oracle.com/otn/java/jdk/11.0.11%2B9/ab2da78f32ed489abb3ff52fd0a02b1c/jdk-11.0.11_windows-x64_bin.exe
          commands:
            1-Install git:
              command: powershell.exe -ExecutionPolicy RemoteSigned -Command Start-Process -FilePath C:DownloadspackagesGit-2.31.1-64-bit.exe -Args '/silent /install' -Verb RunAs -wait;
            2-Install wix:
              command: powershell.exe -ExecutionPolicy RemoteSigned -Command Start-Process -FilePath C:Downloadspackageswix311.exe -Args '/silent /install' -Verb RunAs -wait;
            3-Installing JDK 11:
              command: powershell.exe -ExecutionPolicy RemoteSigned -Command Start-Process -FilePath C:Downloadspackagesjdk-11.0.11_windows-x64_bin.exe -Args '/silent /install' -Verb RunAs -wait;
          services:
            windows:
              cfn-hup:
                enabled: 'true'
                ensureRunning: 'true'
                files:
                - c:cfncfn-hup.conf
                - c:cfnhooks.dcfn-auto-reloader.conf
    Properties:
      InstanceType:
        Ref: InstanceType
      ImageId:
        Fn::FindInMap:
        - AWSRegion2AMI
        - Ref: AWS::Region
        - Windows2012r2
      SecurityGroups:
      - Ref: SharePointFoundationSecurityGroup
      KeyName:
        Ref: KeyName
      UserData:
        Fn::Base64: !Sub |
          <script>
          mkdir C:Downloadspackages
          cfn-init.exe -v --stack ${AWS::StackId} --resource SharePointFoundation --region ${AWS::Region}
          cfn-signal.exe -e %ERRORLEVEL% --stack ${AWS::StackId} --resource SharePointFoundation --region ${AWS::Region}
          </script>

Source: Windows Questions

LEAVE A COMMENT