I am attempting to import a .vmdk
file from an S3 bucket as a snapshot but getting a kernel version error. This file was exported from an AWS Lambda Python script within the same AWS account.
I am following the following export process
instance_id
response = ec2_client.create_image(
InstanceId=instance_id,
Name=name,
Description=description,
)
ami_id = response['ImageId']
# Create an export task to export the image to an S3 bucket
export_task = ec2_client.export_image(
ImageId=ami_id,
DiskImageFormat='VMDK',
S3ExportLocation={
'S3Bucket': S3_BACKUP_BUCKET,
'S3Prefix': s3_object_key,
}
)
export_task_id = export_task['ImageId']
The above code works perfectly and exports the AMI to the S3 bucket
Import Process:
But when I am trying to import the same .vmdk
file which is exported by the AWS Lambda python script using the following command in the AWS CloudShell
aws ec2 import-image \
--disk-containers "[{\"Url\":\"<S3_PATH_OF_VMDK_FILE>\"}]" \
--license-type BYOL \
--platform Linux \
--role-name vmimport
Then I am getting the following error.
"ImportImageTasks": [
{
...
"Status": "deleted",
"StatusMessage": "ClientError: Unsupported kernel version 5.15.0-1055-aws",
"Tags": []
}
]
But, When I create AWS AMI from the browser and then export AMI to the S3 bucket, by following this process, I am able to import the .vmdk
file successfully. But I want to achieve the same if I create the .vmdk
file using the AWS Lambda script.
I got the solution here
Instead of using aws ec2 import-image
command, we can use aws ec2 import-snapshot
to import the image as a snapshot.
The entire command will look like...
aws ec2 import-snapshot --description "My server VM" --disk-container "{\"Description\": \"<DESCRIPTION>\", \"Format\":\"VMDK\", \"UserBucket\": {\"S3Bucket\": \"<BUCKET_NAME>\", \"S3Key\": \"<.vmdk_FILE_WITH_PATH>\"}}"