MCPcopy
hub / github.com/serverless/serverless / update

Method update

packages/serverless/lib/plugins/aws/dev/index.js:567–721  ·  view source on GitHub ↗

* Updates the serverless service configuration with dev mode config needed for the shim to work. Specifically: * 1. Update all AWS Lambda functions' IAM roles to allow all IoT actions. * 2. Update all AWS Lambad function's handler to 'index.handler' as set in the shim * 3. Update all

()

Source from the content-addressed store, hash-verified

565 * @throws {Error} Throws an error if retrieving the IoT endpoint fails.
566 */
567 async update() {
568 logger.debug('Updating service configuration for dev mode')
569 // Makes sure we don't mutate the original IAM configuration
570 this.originalIamConfig = _.cloneDeep(this.serverless.service.provider.iam)
571
572 // Makes sure we support the old iam role statements syntax
573 const oldIamRoleStatements = _.get(
574 this.serverless.service.provider,
575 'iamRoleStatements',
576 [],
577 )
578
579 // Makes sure we support the new iam role statements syntax
580 const newIamRoleStatements = _.get(
581 this.serverless.service.provider,
582 'iam.role.statements',
583 [],
584 )
585
586 // Makes sure we don't overwrite existing IAM configurations
587 const iamRoleStatements = [...oldIamRoleStatements, ...newIamRoleStatements]
588
589 iamRoleStatements.push({
590 Effect: 'Allow',
591 Action: ['iot:*'],
592 Resource: '*',
593 })
594
595 _.set(
596 this.serverless.service.provider,
597 'iam.role.statements',
598 iamRoleStatements,
599 )
600
601 // The IoT endpoint is fetched and passed to the lambda function as env var to be used by the shim
602 const iotEndpoint = await this.getIotEndpoint()
603 const serviceName = this.serverless.service.getServiceName()
604 const stageName = this.serverless.getProvider('aws').getStage()
605 const localRuntimeVersion = process.version.split('.')[0].replace('v', '')
606 const localRuntime = `nodejs${localRuntimeVersion}.x`
607 const runtimeForShim = AWS_LAMBDA_SUPPORTED_NODE_RUNTIMES.includes(
608 localRuntime,
609 )
610 ? localRuntime
611 : 'nodejs20.x'
612 let atLeastOneRuntimeVersionMismatch = false
613
614 if (runtimeForShim !== localRuntime) {
615 logger.warning(
616 `Your local machine is using Node.js v${localRuntimeVersion}, which is not yet supported by AWS Lambda. Falling back to ${runtimeForShim} for dev mode deployment.`,
617 )
618 }
619
620 const allFunctions = this.serverless.service.getAllFunctions()
621
622 const notNodeFunction = allFunctions.find((functionName) => {
623 const functionConfig = this.serverless.service.getFunction(functionName)
624

Callers 15

devMethod · 0.95
packRequirementsFunction · 0.45
zipRequirementsFunction · 0.45
layerRequirementsFunction · 0.45
uvToRequirementsFunction · 0.45
installRequirementsFunction · 0.45
injectAllRequirementsFunction · 0.45
pipfileToRequirementsFunction · 0.45
emitMsgFunction · 0.45
updateProgressMethod · 0.45
deployFunctionMethod · 0.45
uploadCloudFormationFileFunction · 0.45

Calls 11

getIotEndpointMethod · 0.95
debugMethod · 0.80
setMethod · 0.80
getServiceNameMethod · 0.80
warningMethod · 0.80
getAllFunctionsMethod · 0.80
getMethod · 0.45
getStageMethod · 0.45
getProviderMethod · 0.45
getFunctionMethod · 0.45

Tested by

no test coverage detected