aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 2.83 kB
JavaScript
;var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.FunctionUrl=exports.HttpMethod=exports.FunctionUrlAuthType=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),iam=require("../../aws-iam"),core_1=require("../../core"),lambda_generated_1=require("./lambda.generated");var FunctionUrlAuthType;(function(FunctionUrlAuthType2){FunctionUrlAuthType2.AWS_IAM="AWS_IAM",FunctionUrlAuthType2.NONE="NONE"})(FunctionUrlAuthType=exports.FunctionUrlAuthType||(exports.FunctionUrlAuthType={}));var HttpMethod;(function(HttpMethod2){HttpMethod2.GET="GET",HttpMethod2.PUT="PUT",HttpMethod2.HEAD="HEAD",HttpMethod2.POST="POST",HttpMethod2.DELETE="DELETE",HttpMethod2.PATCH="PATCH",HttpMethod2.OPTIONS="OPTIONS",HttpMethod2.ALL="*"})(HttpMethod=exports.HttpMethod||(exports.HttpMethod={}));class FunctionUrl extends core_1.Resource{constructor(scope,id,props){super(scope,id);try{jsiiDeprecationWarnings.aws_cdk_lib_aws_lambda_FunctionUrlProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,FunctionUrl),error}if(this.instanceOfVersion(props.function))throw new Error("FunctionUrl cannot be used with a Version");const{targetFunction,alias}=this.instanceOfAlias(props.function)?{targetFunction:props.function.version.lambda,alias:props.function}:{targetFunction:props.function,alias:void 0},resource=new lambda_generated_1.CfnUrl(this,"Resource",{authType:props.authType??FunctionUrlAuthType.AWS_IAM,cors:props.cors?this.renderCors(props.cors):void 0,targetFunctionArn:targetFunction.functionArn,qualifier:alias?.aliasName});alias?.node.defaultChild!=null&&resource.node.addDependency(alias.node.defaultChild),this.url=resource.attrFunctionUrl,this.functionArn=resource.attrFunctionArn,this.function=props.function,props.authType===FunctionUrlAuthType.NONE&&props.function.addPermission("invoke-function-url",{principal:new iam.AnyPrincipal,action:"lambda:InvokeFunctionUrl",functionUrlAuthType:props.authType})}grantInvokeUrl(grantee){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantInvokeUrl),error}return this.function.grantInvokeUrl(grantee)}instanceOfVersion(fn){return"version"in fn&&!this.instanceOfAlias(fn)}instanceOfAlias(fn){return"aliasName"in fn}renderCors(cors){return{allowCredentials:cors.allowCredentials,allowHeaders:cors.allowedHeaders,allowMethods:cors.allowedMethods??[HttpMethod.ALL],allowOrigins:cors.allowedOrigins,exposeHeaders:cors.exposedHeaders,maxAge:cors.maxAge?.toSeconds()}}}exports.FunctionUrl=FunctionUrl,_a=JSII_RTTI_SYMBOL_1,FunctionUrl[_a]={fqn:"aws-cdk-lib.aws_lambda.FunctionUrl",version:"2.70.0"};