aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 16.7 kB
JavaScript
"use strict";var _a,_b,_c,_d,_e,_f,_g,_h;Object.defineProperty(exports,"__esModule",{value:!0}),exports.LookupMachineImage=exports.GenericWindowsImage=exports.GenericLinuxImage=exports.AmazonLinuxKernel=exports.AmazonLinuxImage=exports.WindowsImage=exports.ResolveSsmParameterAtLaunchImage=exports.GenericSSMParameterImage=exports.MachineImage=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var amazon_linux_2022_1=()=>{var tmp=require("./amazon-linux-2022");return amazon_linux_2022_1=()=>tmp,tmp},amazon_linux_2023_1=()=>{var tmp=require("./amazon-linux-2023");return amazon_linux_2023_1=()=>tmp,tmp},amazon_linux2_1=()=>{var tmp=require("./amazon-linux2");return amazon_linux2_1=()=>tmp,tmp},common_1=()=>{var tmp=require("./common");return common_1=()=>tmp,tmp},utils_1=()=>{var tmp=require("./utils");return utils_1=()=>tmp,tmp},ssm=()=>{var tmp=require("../../../aws-ssm");return ssm=()=>tmp,tmp},cxschema=()=>{var tmp=require("../../../cloud-assembly-schema");return cxschema=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp},user_data_1=()=>{var tmp=require("../user-data");return user_data_1=()=>tmp,tmp},windows_versions_1=()=>{var tmp=require("../windows-versions");return windows_versions_1=()=>tmp,tmp};class MachineImage{static latestWindows(version,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_WindowsVersion(version),jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_WindowsImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.latestWindows),error}return new WindowsImage(version,props)}static latestAmazonLinux2(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_AmazonLinux2ImageSsmParameterProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.latestAmazonLinux2),error}return new(amazon_linux2_1()).AmazonLinux2ImageSsmParameter({cachedInContext:!1,...props,kernel:amazon_linux2_1().AmazonLinux2Kernel.CDK_LATEST})}static latestAmazonLinux2022(props){try{jsiiDeprecationWarnings().print("aws-cdk-lib.aws_ec2.MachineImage#latestAmazonLinux2022","- use latestAmazonLinux2023() instead"),jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_AmazonLinux2022ImageSsmParameterProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.latestAmazonLinux2022),error}return new(amazon_linux_2022_1()).AmazonLinux2022ImageSsmParameter({cachedInContext:!1,...props,kernel:amazon_linux_2022_1().AmazonLinux2022Kernel.CDK_LATEST})}static latestAmazonLinux2023(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_AmazonLinux2023ImageSsmParameterProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.latestAmazonLinux2023),error}return new(amazon_linux_2023_1()).AmazonLinux2023ImageSsmParameter({cachedInContext:!1,...props,kernel:amazon_linux_2023_1().AmazonLinux2023Kernel.CDK_LATEST})}static latestAmazonLinux(props){try{jsiiDeprecationWarnings().print("aws-cdk-lib.aws_ec2.MachineImage#latestAmazonLinux","use MachineImage.latestAmazonLinux2 instead"),jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_AmazonLinuxImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.latestAmazonLinux),error}return new AmazonLinuxImage(props)}static genericLinux(amiMap,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_GenericLinuxImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.genericLinux),error}return new GenericLinuxImage(amiMap,props)}static genericWindows(amiMap,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_GenericWindowsImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.genericWindows),error}return new GenericWindowsImage(amiMap,props)}static fromSSMParameter(parameterName,os,userData){return new GenericSSMParameterImage(parameterName,os,userData)}static fromSsmParameter(parameterName,options){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_SsmParameterImageOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromSsmParameter),error}return new GenericSsmParameterImage(parameterName,options)}static resolveSsmParameterAtLaunch(parameterName,options){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_SsmParameterImageOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.resolveSsmParameterAtLaunch),error}return new ResolveSsmParameterAtLaunchImage(parameterName,options)}static lookup(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_LookupMachineImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.lookup),error}return new LookupMachineImage(props)}}exports.MachineImage=MachineImage,_a=JSII_RTTI_SYMBOL_1,MachineImage[_a]={fqn:"aws-cdk-lib.aws_ec2.MachineImage",version:"2.185.0"};class GenericSSMParameterImage{constructor(parameterName,os,userData){this.os=os,this.userData=userData;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_OperatingSystemType(os),jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_UserData(userData)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,GenericSSMParameterImage),error}this.parameterName=parameterName}getImage(scope){return{imageId:ssm().StringParameter.valueForTypedStringParameterV2(scope,this.parameterName,ssm().ParameterValueType.AWS_EC2_IMAGE_ID),osType:this.os,userData:this.userData??(this.os===common_1().OperatingSystemType.WINDOWS?user_data_1().UserData.forWindows():user_data_1().UserData.forLinux())}}}exports.GenericSSMParameterImage=GenericSSMParameterImage,_b=JSII_RTTI_SYMBOL_1,GenericSSMParameterImage[_b]={fqn:"aws-cdk-lib.aws_ec2.GenericSSMParameterImage",version:"2.185.0"};class ResolveSsmParameterAtLaunchImage{constructor(parameterName,props={}){this.props=props;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_SsmParameterImageOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,ResolveSsmParameterAtLaunchImage),error}this.parameterName=parameterName}getImage(_){const versionString=this.props.parameterVersion?`:${this.props.parameterVersion}`:"",osType=this.props.os??common_1().OperatingSystemType.LINUX;return{imageId:`resolve:ssm:${this.parameterName}${versionString}`,osType,userData:this.props.userData??(osType===common_1().OperatingSystemType.WINDOWS?user_data_1().UserData.forWindows():user_data_1().UserData.forLinux())}}}exports.ResolveSsmParameterAtLaunchImage=ResolveSsmParameterAtLaunchImage,_c=JSII_RTTI_SYMBOL_1,ResolveSsmParameterAtLaunchImage[_c]={fqn:"aws-cdk-lib.aws_ec2.ResolveSsmParameterAtLaunchImage",version:"2.185.0"};class GenericSsmParameterImage{constructor(parameterName,props={}){this.parameterName=parameterName,this.props=props}getImage(scope){const imageId=(0,utils_1().lookupImage)(scope,this.props.cachedInContext,this.parameterName),osType=this.props.os??common_1().OperatingSystemType.LINUX;return{imageId,osType,userData:this.props.userData??(osType===common_1().OperatingSystemType.WINDOWS?user_data_1().UserData.forWindows():user_data_1().UserData.forLinux())}}}class WindowsImage extends GenericSSMParameterImage{constructor(version,props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_WindowsVersion(version),jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_WindowsImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,WindowsImage),error}const nonDeprecatedVersionName=WindowsImage.DEPRECATED_VERSION_NAME_MAP[version]??version;super("/aws/service/ami-windows-latest/"+nonDeprecatedVersionName,common_1().OperatingSystemType.WINDOWS,props.userData)}}exports.WindowsImage=WindowsImage,_d=JSII_RTTI_SYMBOL_1,WindowsImage[_d]={fqn:"aws-cdk-lib.aws_ec2.WindowsImage",version:"2.185.0"},WindowsImage.DEPRECATED_VERSION_NAME_MAP={[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2016_GERMAL_FULL_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2016_GERMAN_FULL_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_R2_SP1_PORTUGESE_BRAZIL_64BIT_CORE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_R2_SP1_PORTUGUESE_BRAZIL_64BIT_CORE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2016_PORTUGESE_PORTUGAL_FULL_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2016_PORTUGUESE_PORTUGAL_FULL_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_R2_RTM_PORTUGESE_BRAZIL_64BIT_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_R2_RTM_PORTUGUESE_BRAZIL_64BIT_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_R2_RTM_PORTUGESE_PORTUGAL_64BIT_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_R2_RTM_PORTUGUESE_PORTUGAL_64BIT_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2016_PORTUGESE_BRAZIL_FULL_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2016_PORTUGUESE_BRAZIL_FULL_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_SP2_PORTUGESE_BRAZIL_64BIT_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_SP2_PORTUGUESE_BRAZIL_64BIT_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_RTM_PORTUGESE_BRAZIL_64BIT_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_RTM_PORTUGUESE_BRAZIL_64BIT_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2008_R2_SP1_PORTUGESE_BRAZIL_64BIT_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2008_R2_SP1_PORTUGUESE_BRAZIL_64BIT_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2008_SP2_PORTUGESE_BRAZIL_32BIT_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2008_SP2_PORTUGUESE_BRAZIL_32BIT_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_RTM_PORTUGESE_PORTUGAL_64BIT_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2012_RTM_PORTUGUESE_PORTUGAL_64BIT_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2019_PORTUGESE_BRAZIL_FULL_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2019_PORTUGUESE_BRAZIL_FULL_BASE,[windows_versions_1().WindowsVersion.WINDOWS_SERVER_2019_PORTUGESE_PORTUGAL_FULL_BASE]:windows_versions_1().WindowsVersion.WINDOWS_SERVER_2019_PORTUGUESE_PORTUGAL_FULL_BASE};class AmazonLinuxImage extends GenericSSMParameterImage{static ssmParameterName(props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_AmazonLinuxImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.ssmParameterName),error}const generation=props&&props.generation||common_1().AmazonLinuxGeneration.AMAZON_LINUX,edition=props&&props.edition||common_1().AmazonLinuxEdition.STANDARD,cpu=props&&props.cpuType||common_1().AmazonLinuxCpuType.X86_64;let kernel=props&&props.kernel||void 0,virtualization,storage;if(generation===common_1().AmazonLinuxGeneration.AMAZON_LINUX_2022){if(kernel=AmazonLinuxKernel.KERNEL5_X,props&&props.storage)throw new Error("Storage parameter does not exist in SSM parameter name for Amazon Linux 2022.");if(props&&props.virtualization)throw new Error("Virtualization parameter does not exist in SSM parameter name for Amazon Linux 2022.")}else if(generation===common_1().AmazonLinuxGeneration.AMAZON_LINUX_2023){if(kernel=AmazonLinuxKernel.KERNEL6_1,props&&props.storage)throw new Error("Storage parameter does not exist in SSM parameter name for Amazon Linux 2023.");if(props&&props.virtualization)throw new Error("Virtualization parameter does not exist in SSM parameter name for Amazon Linux 2023.")}else virtualization=props&&props.virtualization||common_1().AmazonLinuxVirt.HVM,storage=props&&props.storage||common_1().AmazonLinuxStorage.GENERAL_PURPOSE;return"/aws/service/ami-amazon-linux-latest/"+[generation,"ami",edition!==common_1().AmazonLinuxEdition.STANDARD?edition:void 0,kernel,virtualization,cpu,storage].filter(x=>x!==void 0).join("-")}constructor(props={}){super(AmazonLinuxImage.ssmParameterName(props),common_1().OperatingSystemType.LINUX,props.userData),this.props=props;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_AmazonLinuxImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,AmazonLinuxImage),error}this.cachedInContext=props.cachedInContext??!1}getImage(scope){const imageId=(0,utils_1().lookupImage)(scope,this.cachedInContext,this.parameterName),osType=common_1().OperatingSystemType.LINUX;return{imageId,osType,userData:this.props.userData??user_data_1().UserData.forLinux()}}}exports.AmazonLinuxImage=AmazonLinuxImage,_e=JSII_RTTI_SYMBOL_1,AmazonLinuxImage[_e]={fqn:"aws-cdk-lib.aws_ec2.AmazonLinuxImage",version:"2.185.0"};var AmazonLinuxKernel;(function(AmazonLinuxKernel2){AmazonLinuxKernel2.KERNEL5_X="kernel-5.10",AmazonLinuxKernel2.KERNEL6_1="kernel-6.1"})(AmazonLinuxKernel||(exports.AmazonLinuxKernel=AmazonLinuxKernel={}));class GenericLinuxImage{constructor(amiMap,props={}){this.amiMap=amiMap,this.props=props;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_GenericLinuxImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,GenericLinuxImage),error}}getImage(scope){const userData=this.props.userData??user_data_1().UserData.forLinux(),osType=common_1().OperatingSystemType.LINUX,region=core_1().Stack.of(scope).region;if(core_1().Token.isUnresolved(region)){const mapping={};for(const[rgn,ami]of Object.entries(this.amiMap))mapping[rgn]={ami};return{imageId:new(core_1()).CfnMapping(scope,"AmiMap",{mapping}).findInMap(core_1().Aws.REGION,"ami"),userData,osType}}const imageId=region!=="test-region"?this.amiMap[region]:"ami-12345";if(!imageId)throw new Error(`Unable to find AMI in AMI map: no AMI specified for region '${region}'`);return{imageId,userData,osType}}}exports.GenericLinuxImage=GenericLinuxImage,_f=JSII_RTTI_SYMBOL_1,GenericLinuxImage[_f]={fqn:"aws-cdk-lib.aws_ec2.GenericLinuxImage",version:"2.185.0"};class GenericWindowsImage{constructor(amiMap,props={}){this.amiMap=amiMap,this.props=props;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_GenericWindowsImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,GenericWindowsImage),error}}getImage(scope){const userData=this.props.userData??user_data_1().UserData.forWindows(),osType=common_1().OperatingSystemType.WINDOWS,region=core_1().Stack.of(scope).region;if(core_1().Token.isUnresolved(region)){const mapping={};for(const[rgn,ami]of Object.entries(this.amiMap))mapping[rgn]={ami};return{imageId:new(core_1()).CfnMapping(scope,"AmiMap",{mapping}).findInMap(core_1().Aws.REGION,"ami"),userData,osType}}const imageId=region!=="test-region"?this.amiMap[region]:"ami-12345";if(!imageId)throw new Error(`Unable to find AMI in AMI map: no AMI specified for region '${region}'`);return{imageId,userData,osType}}}exports.GenericWindowsImage=GenericWindowsImage,_g=JSII_RTTI_SYMBOL_1,GenericWindowsImage[_g]={fqn:"aws-cdk-lib.aws_ec2.GenericWindowsImage",version:"2.185.0"};class LookupMachineImage{constructor(props){this.props=props;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ec2_LookupMachineImageProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,LookupMachineImage),error}}getImage(scope){const filters={name:[this.props.name],state:["available"],"image-type":["machine"],platform:this.props.windows?["windows"]:void 0};Object.assign(filters,this.props.filters);const value=core_1().ContextProvider.getValue(scope,{provider:cxschema().ContextProvider.AMI_PROVIDER,props:{owners:this.props.owners,filters},dummyValue:"ami-1234"}).value;if(typeof value!="string")throw new Error(`Response to AMI lookup invalid, got: ${value}`);const osType=this.props.windows?common_1().OperatingSystemType.WINDOWS:common_1().OperatingSystemType.LINUX;return{imageId:value,osType,userData:this.props.userData??user_data_1().UserData.forOperatingSystem(osType)}}}exports.LookupMachineImage=LookupMachineImage,_h=JSII_RTTI_SYMBOL_1,LookupMachineImage[_h]={fqn:"aws-cdk-lib.aws_ec2.LookupMachineImage",version:"2.185.0"};