lambda-issuer-acmpca/main.py [66:145]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def deploy_thing( device_id, certificate_arn ):
    iot = boto3.client('iot')

    # Identify if an existing Thing exists with the device ID. If yes, then use
    # that Thing for certificate attachment.  Otherwise, create a new Thing.

    thing_name = None
    
    try:
        iot.describe_thing( thingName = device_id )
        thing_name = device_id
    except:
        print( "Thing [{}] does not exist. Will create.".format( device_id ) )

    if ( thing_name == None ):
        try:
            iot.create_thing( thingName = device_id )
            thing_name = device_id
        except:
            print( "Thing [{}] does not exist and failed to create.".format( device_id ) )
            return False

    # Attach the Thing to the Certificate.
    try:
        iot.attach_thing_principal( thingName = thing_name, principal = certificate_arn )
    except:
        return False

    return True

# The deploy_policy function is an example for deploying a single
# policy for a given SKU. For simplicity, the policy is the same as
# what is deployed for the Python example from the Onboard Wizard.

def deploy_policy( certificate_arn, region, account ):
    policy_name = os.environ["SKUNAME"]
    iot = boto3.client('iot')
    create_policy = False
    
    policy_document = '''{{
  "Version": "2012-10-17",
  "Statement": [
    {{
      "Effect": "Allow",
      "Action": [
        "iot:Publish",
        "iot:Receive"
      ],
      "Resource": [
        "arn:aws:iot:{0}:{1}:topic/sdk/test/java",
        "arn:aws:iot:{0}:{1}:topic/sdk/test/Python",
        "arn:aws:iot:{0}:{1}:topic/topic_1",
        "arn:aws:iot:{0}:{1}:topic/topic_2"
      ]
    }},
    {{
      "Effect": "Allow",
      "Action": [
        "iot:Subscribe"
      ],
      "Resource": [
        "arn:aws:iot:{0}:{1}:topicfilter/sdk/test/java",
        "arn:aws:iot:{0}:{1}:topicfilter/sdk/test/Python",
        "arn:aws:iot:{0}:{1}:topicfilter/topic_1",
        "arn:aws:iot:{0}:{1}:topicfilter/topic_2"
      ]
    }},
    {{
      "Effect": "Allow",
      "Action": [
        "iot:Connect"
      ],
      "Resource": [
        "arn:aws:iot:{0}:{1}:client/sdk-java",
        "arn:aws:iot:{0}:{1}:client/basicPubSub",
        "arn:aws:iot:{0}:{1}:client/sdk-nodejs-*"
      ]
    }}
  ]
}}'''
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



lambda-issuer-iotcore/main.py [31:110]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def deploy_thing( device_id, certificate_arn ):
    iot = boto3.client('iot')

    # Identify if an existing Thing exists with the device ID. If yes, then use
    # that Thing for certificate attachment.  Otherwise, create a new Thing.

    thing_name = None
    
    try:
        iot.describe_thing( thingName = device_id )
        thing_name = device_id
    except:
        print( "Thing [{}] does not exist. Will create.".format( device_id ) )

    if ( thing_name == None ):
        try:
            iot.create_thing( thingName = device_id )
            thing_name = device_id
        except:
            print( "Thing [{}] does not exist and failed to create.".format( device_id ) )
            return False

    # Attach the Thing to the Certificate.
    try:
        iot.attach_thing_principal( thingName = thing_name, principal = certificate_arn )
    except:
        return False

    return True

# The deploy_policy function is an example for deploying a single
# policy for a given SKU. For simplicity, the policy is the same as
# what is deployed for the Python example from the Onboard Wizard.

def deploy_policy( certificate_arn, region, account ):
    policy_name = os.environ["SKUNAME"]
    iot = boto3.client('iot')
    create_policy = False
    
    policy_document = '''{{
  "Version": "2012-10-17",
  "Statement": [
    {{
      "Effect": "Allow",
      "Action": [
        "iot:Publish",
        "iot:Receive"
      ],
      "Resource": [
        "arn:aws:iot:{0}:{1}:topic/sdk/test/java",
        "arn:aws:iot:{0}:{1}:topic/sdk/test/Python",
        "arn:aws:iot:{0}:{1}:topic/topic_1",
        "arn:aws:iot:{0}:{1}:topic/topic_2"
      ]
    }},
    {{
      "Effect": "Allow",
      "Action": [
        "iot:Subscribe"
      ],
      "Resource": [
        "arn:aws:iot:{0}:{1}:topicfilter/sdk/test/java",
        "arn:aws:iot:{0}:{1}:topicfilter/sdk/test/Python",
        "arn:aws:iot:{0}:{1}:topicfilter/topic_1",
        "arn:aws:iot:{0}:{1}:topicfilter/topic_2"
      ]
    }},
    {{
      "Effect": "Allow",
      "Action": [
        "iot:Connect"
      ],
      "Resource": [
        "arn:aws:iot:{0}:{1}:client/sdk-java",
        "arn:aws:iot:{0}:{1}:client/basicPubSub",
        "arn:aws:iot:{0}:{1}:client/sdk-nodejs-*"
      ]
    }}
  ]
}}'''
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



