UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 14.9 kB
"use strict";var __esDecorate=exports&&exports.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(f!==void 0&&typeof f!="function")throw new TypeError("Function expected");return f}for(var kind=contextIn.kind,key=kind==="getter"?"get":kind==="setter"?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),_,done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]=p==="access"?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])(kind==="accessor"?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if(kind==="accessor"){if(result===void 0)continue;if(result===null||typeof result!="object")throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&(kind==="field"?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0},__runInitializers=exports&&exports.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CodeInterpreterCustom=exports.CodeInterpreterCustomBase=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var perms=()=>{var tmp=require("./perms");return perms=()=>tmp,tmp},agent_core=()=>{var tmp=require("../../../aws-bedrockagentcore");return agent_core=()=>tmp,tmp},aws_cloudwatch_1=()=>{var tmp=require("../../../aws-cloudwatch");return aws_cloudwatch_1=()=>tmp,tmp},ec2=()=>{var tmp=require("../../../aws-ec2");return ec2=()=>tmp,tmp},iam=()=>{var tmp=require("../../../aws-iam");return iam=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp},helpers_internal_1=()=>{var tmp=require("../../../core/lib/helpers-internal");return helpers_internal_1=()=>tmp,tmp},metadata_resource_1=()=>{var tmp=require("../../../core/lib/metadata-resource");return metadata_resource_1=()=>tmp,tmp},prop_injectable_1=()=>{var tmp=require("../../../core/lib/prop-injectable");return prop_injectable_1=()=>tmp,tmp},validation_helpers_1=()=>{var tmp=require("../common/validation-helpers");return validation_helpers_1=()=>tmp,tmp},network_configuration_1=()=>{var tmp=require("../network/network-configuration");return network_configuration_1=()=>tmp,tmp};const CODE_INTERPRETER_NAME_MIN_LENGTH=1,CODE_INTERPRETER_NAME_MAX_LENGTH=48,CODE_INTERPRETER_TAG_MIN_LENGTH=1,CODE_INTERPRETER_TAG_MAX_LENGTH=256;class CodeInterpreterCustomBase extends core_1().Resource{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.CodeInterpreterCustomBase",version:"2.257.0"};get codeInterpreterCustomRef(){return{codeInterpreterId:this.codeInterpreterId,codeInterpreterArn:this.codeInterpreterArn}}get connections(){if(!this._connections)throw new(core_1()).ValidationError((0,helpers_internal_1().lit)`VpcNotConfigured`,"Cannot manage network access without configuring a VPC",this);return this._connections}_connections;constructor(scope,id,props={}){super(scope,id,props);try{jsiiDeprecationWarnings().aws_cdk_lib_ResourceProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,CodeInterpreterCustomBase),error}}grant(grantee,...actions){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grant),error}return iam().Grant.addToPrincipal({grantee,resourceArns:[this.codeInterpreterCustomRef.codeInterpreterArn],actions})}grantRead(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.grantRead),error}const resourceSpecificGrant=this.grant(grantee,...perms().CODE_INTERPRETER_READ_PERMS),allResourceGrant=iam().Grant.addToPrincipal({grantee,resourceArns:["*"],actions:perms().CODE_INTERPRETER_LIST_PERMS});return resourceSpecificGrant.combine(allResourceGrant)}grantUse(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.grantUse),error}return this.grant(grantee,...perms().CODE_INTERPRETER_USE_PERMS)}grantInvoke(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.grantInvoke),error}return this.grant(grantee,...perms().CODE_INTERPRETER_INVOKE_PERMS)}metric(metricName,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metric),error}const metricProps={namespace:"AWS/Bedrock-AgentCore",metricName,...props,dimensionsMap:{Resource:this.codeInterpreterCustomRef.codeInterpreterArn,...props?.dimensionsMap}};return this.configureMetric(metricProps)}metricForApiOperation(metricName,operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricForApiOperation),error}return this.metric(metricName,{dimensionsMap:{Operation:operation},...props})}metricLatencyForApiOperation(operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricLatencyForApiOperation),error}return this.metricForApiOperation("Latency",operation,{statistic:aws_cloudwatch_1().Stats.AVERAGE,...props})}metricInvocationsForApiOperation(operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricInvocationsForApiOperation),error}return this.metricForApiOperation("Invocations",operation,{statistic:aws_cloudwatch_1().Stats.SUM,...props})}metricErrorsForApiOperation(operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricErrorsForApiOperation),error}return this.metricForApiOperation("Errors",operation,{statistic:aws_cloudwatch_1().Stats.SUM,...props})}metricThrottlesForApiOperation(operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricThrottlesForApiOperation),error}return this.metricForApiOperation("Throttles",operation,{statistic:aws_cloudwatch_1().Stats.SUM,...props})}metricSystemErrorsForApiOperation(operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricSystemErrorsForApiOperation),error}return this.metricForApiOperation("SystemErrors",operation,{statistic:aws_cloudwatch_1().Stats.SUM,...props})}metricUserErrorsForApiOperation(operation,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricUserErrorsForApiOperation),error}return this.metricForApiOperation("UserErrors",operation,{statistic:aws_cloudwatch_1().Stats.SUM,...props})}metricSessionDuration(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricSessionDuration),error}return this.metric("Duration",{dimensionsMap:{Operation:"CodeInterpreterSession"},statistic:aws_cloudwatch_1().Stats.AVERAGE,...props})}configureMetric(props){return new(aws_cloudwatch_1()).Metric({...props,region:props?.region??this.stack.region,account:props?.account??this.stack.account})}}exports.CodeInterpreterCustomBase=CodeInterpreterCustomBase;let CodeInterpreterCustom=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=CodeInterpreterCustomBase;var CodeInterpreterCustom2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),CodeInterpreterCustom2=_classThis=_classDescriptor.value,_metadata&&Object.defineProperty(_classThis,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_bedrockagentcore.CodeInterpreterCustom",version:"2.257.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-bedrockagentcore.CodeInterpreterCustom";static fromCodeInterpreterCustomAttributes(scope,id,attrs){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_CodeInterpreterCustomAttributes(attrs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromCodeInterpreterCustomAttributes),error}class Import extends CodeInterpreterCustomBase{codeInterpreterArn=attrs.codeInterpreterArn;codeInterpreterId=core_1().Arn.split(attrs.codeInterpreterArn,core_1().ArnFormat.SLASH_RESOURCE_NAME).resourceName;executionRole=iam().Role.fromRoleArn(scope,`${id}Role`,attrs.roleArn);lastUpdatedAt=attrs.lastUpdatedAt;grantPrincipal=this.executionRole;status=attrs.status;createdAt=attrs.createdAt;constructor(s,i){super(s,i),this.grantPrincipal=this.executionRole||new(iam()).UnknownPrincipal({resource:this}),attrs.securityGroups&&(this._connections=new(ec2()).Connections({securityGroups:attrs.securityGroups}))}}return new Import(scope,id)}codeInterpreterArn;codeInterpreterId;codeInterpreterCustomName;description;networkConfiguration;status;createdAt;lastUpdatedAt;failureReason;executionRole;grantPrincipal;tags;__resource;constructor(scope,id,props={}){super(scope,id,{physicalName:props.codeInterpreterCustomName??core_1().Lazy.string({produce:()=>core_1().Names.uniqueResourceName(this,{maxLength:48})})});try{jsiiDeprecationWarnings().aws_cdk_lib_aws_bedrockagentcore_CodeInterpreterCustomProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,CodeInterpreterCustom2),error}(0,metadata_resource_1().addConstructMetadata)(this,props),this.codeInterpreterCustomName=this.physicalName,this.description=props.description,this.networkConfiguration=props.networkConfiguration??network_configuration_1().CodeInterpreterNetworkConfiguration.usingPublicNetwork(),this.executionRole=props.executionRole??this._createCodeInterpreterRole(),this.grantPrincipal=this.executionRole,this.tags=props.tags,(0,validation_helpers_1().throwIfInvalid)(this._validateCodeInterpreterName,this.codeInterpreterCustomName),(0,validation_helpers_1().throwIfInvalid)(this._validateCodeInterpreterTags,this.tags),this.networkConfiguration.connections&&(this._connections=this.networkConfiguration.connections);const cfnProps={name:this.codeInterpreterCustomName,description:this.description,networkConfiguration:core_1().Lazy.any({produce:()=>this.networkConfiguration._render(this._connections)}),executionRoleArn:this.executionRole?.roleArn,tags:this.tags};this.__resource=new(agent_core()).CfnCodeInterpreterCustom(this,"Resource",cfnProps),this.codeInterpreterId=this.__resource.attrCodeInterpreterId,this.codeInterpreterArn=this.__resource.attrCodeInterpreterArn,this.status=this.__resource.attrStatus,this.createdAt=this.__resource.attrCreatedAt,this.lastUpdatedAt=this.__resource.attrLastUpdatedAt,this.failureReason=this.__resource.attrFailureReason}_validateCodeInterpreterName=name=>{let errors=[];errors.push(...(0,validation_helpers_1().validateStringFieldLength)({value:name,fieldName:"Code interpreter name",minLength:CODE_INTERPRETER_NAME_MIN_LENGTH,maxLength:CODE_INTERPRETER_NAME_MAX_LENGTH}));const validNamePattern=/^[a-zA-Z][a-zA-Z0-9_]{0,47}$/;return errors.push(...(0,validation_helpers_1().validateFieldPattern)(name,"Code interpreter name",validNamePattern)),errors};_validateCodeInterpreterTags=tags=>{let errors=[];if(!tags)return errors;for(const[key,value]of Object.entries(tags)){key.toLowerCase().startsWith("aws:")&&errors.push(`Tag key "${key}" cannot start with "aws:" as this prefix is reserved by AWS`),errors.push(...(0,validation_helpers_1().validateStringFieldLength)({value:key,fieldName:"Tag key",minLength:CODE_INTERPRETER_TAG_MIN_LENGTH,maxLength:CODE_INTERPRETER_TAG_MAX_LENGTH}));const validKeyPattern=/^[a-zA-Z0-9\s._:/=+@-]*$/;errors.push(...(0,validation_helpers_1().validateFieldPattern)(key,"Tag key",validKeyPattern)),errors.push(...(0,validation_helpers_1().validateStringFieldLength)({value,fieldName:"Tag value",minLength:CODE_INTERPRETER_TAG_MIN_LENGTH,maxLength:CODE_INTERPRETER_TAG_MAX_LENGTH}));const validValuePattern=/^[a-zA-Z0-9\s._:/=+@-]*$/;errors.push(...(0,validation_helpers_1().validateFieldPattern)(value,"Tag value",validValuePattern))}return errors};_createCodeInterpreterRole(){return new(iam()).Role(this,"ServiceRole",{assumedBy:new(iam()).ServicePrincipal("bedrock-agentcore.amazonaws.com",{conditions:{StringEquals:{"aws:SourceAccount":core_1().Stack.of(this).account},ArnLike:{"aws:SourceArn":core_1().Arn.format({service:"bedrock-agentcore",resource:"code-interpreter-custom",resourceName:`${this.codeInterpreterCustomName}*`},core_1().Stack.of(this))}}})})}static{__runInitializers(_classThis,_classExtraInitializers)}};return CodeInterpreterCustom2=_classThis})();exports.CodeInterpreterCustom=CodeInterpreterCustom;