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 *RuntimeError: 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-xyz"
# 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 *RuntimeError: The Product License has not been initialized."