* 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
()
| 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 |
no test coverage detected