public getSolutionGreengrassDefaultDefinitions()

in source/lambda/lib/greengrass-handler.ts [86:239]


  public getSolutionGreengrassDefaultDefinitions(input: GreengrassHandlerTypes.DefaultDefinitionsRequest): GreengrassHandlerTypes.DefaultDefinitionResponse {
    logger.log(LoggingLevel.DEBUG, `Getting solution greengrass default definitions: ${JSON.stringify(input, null, 2)}`);

    const functions: any[] = [{
      FunctionArn: 'arn:aws:lambda:::function:GGStreamManager:1',
      FunctionConfiguration: {
        MemorySize: 4194304,
        Pinned: true,
        Timeout: 3
      },
      Id: 'StreamManager'
    }];
    const subscriptions: any[] = [];

    // If the Lambda function alias ARN is not provided, it should be deleting the connection.
    if (input.collectorLambdaFunctionAliasArn) {
      functions.push({
        FunctionArn: input.collectorLambdaFunctionAliasArn,
        FunctionConfiguration: {
          EncodingType: 'json',
          Environment: {
            AccessSysfs: false,
            ResourceAccessPolicies: [
              {
                Permission: 'rw',
                ResourceId: 'M2C2LocalResourceId'
              },
            ],
            Variables: {
              AREA: this.hierarchy.area,
              CONNECTION_GG_STREAM_NAME: `m2c2_${this.connectionName}_stream`,
              MACHINE_NAME: this.hierarchy.machineName,
              PROCESS: this.hierarchy.process,
              SITE_NAME: this.hierarchy.siteName
            }
          },
          Executable: `m2c2_${this.protocol}_connector.function_handler`,
          MemorySize: 128000,
          Pinned: true,
          Timeout: 10
        },
        Id: `Function-id-${this.connectionName}-collector`
      });

      subscriptions.push({
        Id: `${this.connectionName}-to-cloud`,
        Source: 'cloud',
        Subject: `m2c2/job/${this.connectionName}`,
        Target: input.collectorLambdaFunctionAliasArn,
      });

      subscriptions.push({
        Id: `${this.connectionName}-from-collector`,
        Source: input.collectorLambdaFunctionAliasArn,
        Subject: `m2c2/#`,
        Target: 'cloud'
      });
    }

    if (input.publisherLambdaFunctionAliasArn) {
      functions.push({
        FunctionArn: input.publisherLambdaFunctionAliasArn,
        FunctionConfiguration: {
          EncodingType: 'json',
          Environment: {
            AccessSysfs: false,
            ResourceAccessPolicies: [
              {
                Permission: 'rw',
                ResourceId: 'M2C2LocalResourceId'
              },
            ],
            Variables: {
              AREA: this.hierarchy.area,
              CONNECTION_GG_STREAM_NAME: `m2c2_${this.connectionName}_stream`,
              CONNECTION_NAME: this.connectionName,
              KINESIS_STREAM_NAME: KINESIS_STREAM,
              MACHINE_NAME: this.hierarchy.machineName,
              PROCESS: this.hierarchy.process,
              PROTOCOL: this.protocol,
              SEND_TO_IOT_TOPIC: this.sendDataTo.iotTopic ? 'Yes' : undefined,
              SEND_TO_KINESIS_STREAM: this.sendDataTo.kinesisDataStreams ? 'Yes' : undefined,
              SEND_TO_SITEWISE: this.sendDataTo.iotSiteWise ? 'Yes' : undefined,
              SITE_NAME: this.hierarchy.siteName
            }
          },
          Executable: `m2c2_publisher.function_handler`,
          MemorySize: 128000,
          Pinned: true,
          Timeout: 10
        },
        Id: `Function-id-${this.connectionName}-publisher`
      });

      subscriptions.push({
        Id: `${this.connectionName}-from-publisher`,
        Source: input.publisherLambdaFunctionAliasArn,
        Subject: `m2c2/#`,
        Target: 'cloud'
      });
    }

    return {
      Connector: [{
        Id: 'M2C2SitewiseConnector',
        ConnectorArn: `arn:aws:greengrass:${AWS_REGION}::/connectors/IoTSiteWise/versions/11`
      }],
      Core: [],
      Device: [],
      Function: functions,
      Logger: [
        {
          Id: 'M2C2GreengrassFileSystemLogger',
          Type: 'FileSystem',
          Component: 'GreengrassSystem',
          Level: 'INFO',
          Space: 128
        },
        {
          Id: 'GreengrasAWSCloudWatchLogger',
          Type: 'AWSCloudWatch',
          Component: 'GreengrassSystem',
          Level: 'WARN'
        },
        {
          Id: 'M2C2LambdaFileSystemLogger',
          Type: 'FileSystem',
          Component: 'Lambda',
          Level: 'INFO',
          Space: 128
        },
        {
          Id: 'M2C2LambdaAWSCloudWatchLogger',
          Type: 'AWSCloudWatch',
          Component: 'Lambda',
          Level: 'WARN'
        }
      ],
      Resource: [{
        Name: 'M2C2LocalResource',
        Id: 'M2C2LocalResourceId',
        ResourceDataContainer: {
          LocalVolumeResourceData: {
            SourcePath: LOCAL_RESOURCE_PATH,
            DestinationPath: LOCAL_RESOURCE_PATH,
            GroupOwnerSetting: {
              AutoAddGroupOwner: true
            }
          }
        }
      }],
      Subscription: subscriptions
    };
  }