AWSTemplateFormatVersion: '2010-09-09' Description: 'AWS CloudFormation Windows AMI Lookup Example Template: Demonstrates how to dynamically get the most recent Windows AMI ID. This template provisions an EC2 instance with an AMI ID that is based on the selected instance type and Windows OS version. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.' Parameters: InstanceType: Description: EC2 instance type Type: String Default: t2.small AllowedValues: - t1.micro - t2.micro - t2.small - t2.medium - m1.small - m1.medium - m1.large - m1.xlarge - m2.xlarge - m2.2xlarge - m2.4xlarge - m3.medium - m3.large - m3.xlarge - m3.2xlarge - c1.medium - c1.xlarge - c3.large - c3.xlarge - c3.2xlarge - c3.4xlarge - c3.8xlarge - c4.large - c4.xlarge - c4.2xlarge - c4.4xlarge - c4.8xlarge - g2.2xlarge - r3.large - r3.xlarge - r3.2xlarge - r3.4xlarge - r3.8xlarge - i2.xlarge - i2.2xlarge - i2.4xlarge - i2.8xlarge - d2.xlarge - d2.2xlarge - d2.4xlarge - d2.8xlarge - hi1.4xlarge - hs1.8xlarge - cr1.8xlarge - cc2.8xlarge - cg1.4xlarge ConstraintDescription: Must be a valid EC2 instance type. WindowsVersion: Description: Windows Version Type: String Default: Windows Server 2016 Base English 64-bit AllowedValues: - Windows Server 2008 SP2 English 32-bit - Windows Server 2008 SP2 English 64-bit - Windows Server 2008 R2 English 64-bit - Windows Server 2012 RTM English 64-bit - Windows Server 2012 R2 English 64-bit - Windows Server 2016 Base English 64-bit ConstraintDescription: Must be a valid Windows version. ModuleName: Description: The name of the JavaScript file Type: String Default: amilookup-win S3Bucket: Description: The name of the bucket that contains your packaged source Type: String Default: aws-bigdata-blog S3Key: Description: The name of the ZIP package Type: String Default: artifacts/aws-blog-emr-ranger ProjectVersion: Default: 2.0 Description: Project version Type: String AllowedValues: - 2.0 - beta Resources: # SampleInstance: # Type: AWS::EC2::Instance # Properties: # InstanceType: !Ref 'InstanceType' # ImageId: !GetAtt 'AMIInfo.Id' AMIInfo: Type: Custom::AMIInfo Properties: ServiceToken: !GetAtt 'AMIInfoFunction.Arn' Region: !Ref 'AWS::Region' OSName: !Ref 'WindowsVersion' AMIInfoFunction: Type: AWS::Lambda::Function Properties: Code: S3Bucket: !Ref 'S3Bucket' S3Key: !Join ['', [!Ref 'S3Key', '/' , !Ref 'ProjectVersion', '/amilookup-win.zip']] Handler: !Join - '' - - !Ref 'ModuleName' - .handler Role: !GetAtt 'LambdaExecutionRole.Arn' Runtime: nodejs12.x Timeout: '30' LambdaExecutionRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - lambda.amazonaws.com Action: - sts:AssumeRole Path: / Policies: - PolicyName: root PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - logs:CreateLogGroup - logs:CreateLogStream - logs:PutLogEvents Resource: arn:aws:logs:*:*:* - Effect: Allow Action: - ec2:DescribeImages Resource: '*' Outputs: AMIID: Description: The Amazon EC2 instance AMI ID. Value: !GetAtt 'AMIInfo.Id'