UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 4.34 kB
"use strict";var __decorate=exports&&exports.__decorate||function(decorators,target,key,desc){var c=arguments.length,r=c<3?target:desc===null?desc=Object.getOwnPropertyDescriptor(target,key):desc,d;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r},_a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.FunctionUrl=exports.HttpMethod=exports.InvokeMode=exports.FunctionUrlAuthType=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var lambda_generated_1=()=>{var tmp=require("./lambda.generated");return lambda_generated_1=()=>tmp,tmp},iam=()=>{var tmp=require("../../aws-iam");return iam=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},errors_1=()=>{var tmp=require("../../core/lib/errors");return errors_1=()=>tmp,tmp},metadata_resource_1=()=>{var tmp=require("../../core/lib/metadata-resource");return metadata_resource_1=()=>tmp,tmp},FunctionUrlAuthType;(function(FunctionUrlAuthType2){FunctionUrlAuthType2.AWS_IAM="AWS_IAM",FunctionUrlAuthType2.NONE="NONE"})(FunctionUrlAuthType||(exports.FunctionUrlAuthType=FunctionUrlAuthType={}));var InvokeMode;(function(InvokeMode2){InvokeMode2.BUFFERED="BUFFERED",InvokeMode2.RESPONSE_STREAM="RESPONSE_STREAM"})(InvokeMode||(exports.InvokeMode=InvokeMode={}));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=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((0,metadata_resource_1().addConstructMetadata)(this,props),this.instanceOfVersion(props.function))throw new(errors_1()).ValidationError("FunctionUrl cannot be used with a Version",this);const{targetFunction,alias}=this.instanceOfAlias(props.function)?{targetFunction:props.function.version.lambda,alias:props.function}:{targetFunction:props.function,alias:void 0};this.authType=props.authType??FunctionUrlAuthType.AWS_IAM;const resource=new(lambda_generated_1()).CfnUrl(this,"Resource",{authType:this.authType,cors:props.cors?this.renderCors(props.cors):void 0,invokeMode:props.invokeMode,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){if(cors.maxAge&&!cors.maxAge.isUnresolved()&&cors.maxAge.toSeconds()>86400)throw new(errors_1()).ValidationError(`FunctionUrl CORS maxAge should be less than or equal to 86400 secs (got ${cors.maxAge.toSeconds()})`,this);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.185.0"},__decorate([(0,metadata_resource_1().MethodMetadata)()],FunctionUrl.prototype,"grantInvokeUrl",null);