Select to view content in your preferred language

I try to access a python file contains ArcPy functions from AWS lambda to EC2 Instance.

547
2
10-05-2023 08:41 AM
SangeethAmirthanathan
New Contributor

I have a lambda trigger that will execute when i put the FGDB to S3 bucket. this lambda trigger to an EC2 instance python file contains ArcPy functionalities. I am getting an error below

" from ._arcgisscripting import *\r\nRuntimeError: The Product License has not been initialized."

Here is the lambda fucntion

import time
import json
import boto3

def lambda_handler(event, context):
    # boto3 client
    client = boto3.client("ec2")
    ssm = boto3.client("ssm", region_name='us-west-2')

    # getting instance information
    describeInstance = client.describe_instances()

    InstanceId = "i-xxxxxxxxxxxx"

    # Check if the Lambda was triggered by an S3 event
    if 'Records' in event and len(event['Records']) > 0:
        s3_event = event['Records'][0]['s3']
        bucket_name = s3_event['bucket']['name']
        object_key = s3_event['object']['key']

        # Construct the S3 file path
        s3_file_path = f"s3://{bucket_name}/{object_key}"
        
        

        # command to be executed on instance
        response = ssm.send_command(InstanceIds=[InstanceId], DocumentName="AWS-RunPowerShellScript",
                                    Parameters={
                                        "commands": [
                                            f"C:\\Users\\Administrator\\AppData\\Local\\ESRI\\conda\\envs\\arcgispro-py3-clone-1\\python.exe C:\\Users\\Administrator\\Desktop\\Automation\\DownloadZIP.py {s3_file_path}"
                                        ]
                                    })
    
        # fetching command id for the output
        command_id = response["Command"]["CommandId"]
    
        time.sleep(30)
    
        # fetching command output
        output = ssm.get_command_invocation(CommandId=command_id, InstanceId=InstanceId)
        print(output)
    
        return {"statusCode": 200, "body": json.dumps("Run Successful")}

 

I am getting an error when only EC2 instance contains ArcPy functionalities otherwise if I am not getting any error. functions are working fine.

Error

" from ._arcgisscripting import *\r\nRuntimeError: The Product License has not been initialized."

Tags (4)
0 Kudos
2 Replies
AnthonyRyanEQL
Frequent Contributor

Is ArcGIS Pro accessible and licensed to the user that is running the powershell script to invoke the py file?

0 Kudos
SangeethAmirthanathan
New Contributor

ArcGIS pro accessible and licensed on EC2. Also with the same ArcGIS Pro cloned python environment working fine on EC2. there are no error when i run ArcPy related scripts on EC2. On other hand if i run the scripts with lambda function trigger, its throwing an error called 

from ._arcgisscripting import *\r\nRuntimeError: The Product License has not been initialized.

0 Kudos