serverless icon indicating copy to clipboard operation
serverless copied to clipboard

Getting node10 error when trying to deploy this (Python version)

Open DanielWhite21 opened this issue 3 years ago • 0 comments

Im just learning CDK at the mo and have decided to start with something applicable to my job with the ETL pipeline. So apologies if this is not an issue with the code and is my lack of knowledge.

I cannot locate how to set the runtime to a newer version of node for this Lambda runtime of this function.

Getting an error: 20:32:38 | CREATE_FAILED | AWS::Lambda::Function | BucketNotification...094a3db8347ECC3691 Resource handler returned message: "The runtime parameter of nodejs10.x is no longer supported for creating or updating AWS Lambda functions

Looks like it related to the part of the of the template:

    Type: AWS::Lambda::Function
    Properties:
      Description: AWS CloudFormation handler for "Custom::S3BucketNotifications" resources (@aws-cdk/aws-s3)
      Code:
        ZipFile: |-
          exports.handler = (event, context) => {
              // eslint-disable-next-line @typescript-eslint/no-require-imports, import/no-extraneous-dependencies
              const s3 = new (require('aws-sdk').S3)();
              // eslint-disable-next-line @typescript-eslint/no-require-imports
              const https = require('https');
              // eslint-disable-next-line @typescript-eslint/no-require-imports
              const url = require('url');
              log(JSON.stringify(event, undefined, 2));
              const props = event.ResourceProperties;
              if (event.RequestType === 'Delete') {
                  props.NotificationConfiguration = {}; // this is how you clean out notifications
              }
              const req = {
                  Bucket: props.BucketName,
                  NotificationConfiguration: props.NotificationConfiguration,
              };
              return s3.putBucketNotificationConfiguration(req, (err, data) => {
                  log({ err, data });
                  if (err) {
                      return submitResponse('FAILED', err.message + `\nMore information in CloudWatch Log Stream: ${context.logStreamName}`);
                  }
                  else {
                      return submitResponse('SUCCESS');
                  }
              });
              function log(obj) {
                  console.error(event.RequestId, event.StackId, event.LogicalResourceId, obj);
              }
              // eslint-disable-next-line max-len
              // adapted from https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-cfnresponsemodule
              // to allow sending an error messge as a reason.
              function submitResponse(responseStatus, reason) {
                  const responseBody = JSON.stringify({
                      Status: responseStatus,
                      Reason: reason || 'See the details in CloudWatch Log Stream: ' + context.logStreamName,
                      PhysicalResourceId: event.PhysicalResourceId || event.LogicalResourceId,
                      StackId: event.StackId,
                      RequestId: event.RequestId,
                      LogicalResourceId: event.LogicalResourceId,
                      NoEcho: false,
                  });
                  log({ responseBody });
                  const parsedUrl = url.parse(event.ResponseURL);
                  const options = {
                      hostname: parsedUrl.hostname,
                      port: 443,
                      path: parsedUrl.path,
                      method: 'PUT',
                      headers: {
                          'content-type': '',
                          'content-length': responseBody.length,
                      },
                  };
                  const request = https.request(options, (r) => {
                      log({ statusCode: r.statusCode, statusMessage: r.statusMessage });
                      context.done();
                  });
                  request.on('error', (error) => {
                      log({ sendError: error });
                      context.done();
                  });
                  request.write(responseBody);
                  request.end();
              }
          };
      Handler: index.handler
      Role:
        Fn::GetAtt:
          - BucketNotificationsHandler050a0587b7544547bf325f094a3db834RoleB6FB88EC
          - Arn
      Runtime: nodejs10.x
      Timeout: 300
    DependsOn:
      - BucketNotificationsHandler050a0587b7544547bf325f094a3db834RoleDefaultPolicy2CF63D36
      - BucketNotificationsHandler050a0587b7544547bf325f094a3db834RoleB6FB88EC
    Metadata:
      aws:cdk:path: the-eventbridge-etl/BucketNotificationsHandler050a0587b7544547bf325f094a3db834/Resource```

DanielWhite21 avatar Dec 06 '21 16:12 DanielWhite21