constructor()

in cdk/lib/data-ingestion-stack.ts [14:83]


  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const region = props?.env?.region || 'us-east-1'
    const account = props?.env?.account || ''

    /**
     * Create Device.
     * The PetTrackerThing will receives messages from the tracker device or emulator.
     */
    const trackerThing = new iot.CfnThing(this, "IoTDevice", {
      thingName: "PetTrackerThing"
    });

    const trackerCredentials = new CustomCertificateResource(
      this,
      "PetTrackerCredentials",
      {
        account: this.account,
        stackName: this.stackName,
        thingName: trackerThing.ref
      }
    );

    new iot.CfnThingPrincipalAttachment(
      this,
      "PetTrackerThingCredentialAttachment",
      {
        principal: trackerCredentials.certificateArn,
        thingName: trackerThing.ref
      }
    );

    const trackerPolicy = new iot.CfnPolicy(this, "PetTrackerPolicy", {
      policyName: `${trackerThing.thingName}_Policy`,
      policyDocument: {
        Version: "2012-10-17",
        Statement: [
          {
            Effect: "Allow",
            Action: "iot:*",
            Resource: "*"
          }
        ]
      }
    });

    new iot.CfnPolicyPrincipalAttachment(this, "PetTrackerThingPolicyAttachment", {
      policyName: trackerPolicy.policyName!,
      principal: trackerCredentials.certificateArn
    });

    const locationTracker = new CustomTrackerResource(this, 'pettracker-location-tracker', {
      trackerName: "PetTracker",
      region: region,
      account: account
    });

    new PetTrackerPositionLambda(this, 'pettracker-position-lambda', {
      region: region,
      account: account
    });

    new PetTrackerALSLambda(this, 'pettracker-als-lambda', {
      region: region,
      account: account,
      trackerName: locationTracker.trackerName
    });

  }