Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (7k points)

I am trying to import an openssl certificate to AWS ACM using python. But facing an error:

Response:

{

      "errorMessage": "An error occurred (ValidationException) when calling the ImportCertificate operation: The certificate field contains more than one certificate. You can specify only one certificate in this field.",

      "errorType": "ClientError",

      "stackTrace": [

        "  File \"/var/task/lambda_function.py\", line 7, in lambda_handler\n    response = client.import_certificate(\n",

        "  File \"/var/runtime/botocore/client.py\", line 316, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",

        "  File \"/var/runtime/botocore/client.py\", line 626, in _make_api_call\n    raise error_class(parsed_response, operation_name)\n"

      ]

}

My code:

import boto3

client = boto3.client('acm')

def lambda_handler(event, context):

    response = client.import_certificate(

        Certificate='sample.vpn.crt',

        PrivateKey='sample.vpn.key',

        CertificateChain='ca.crt'

    )

Can you help?

1 Answer

0 votes
by (31.9k points)
edited by

As per the boto3 docs, the type of the three parameters should not be strings, but bytes. Try reading the cert files from the package as below:

import boto3

client = boto3.client('acm')

def lambda_handler(event, context):

    certificate=open('sample.vpn.crt', 'rb').read()

    privatekey=open('sample.vpn.key', 'rb').read()

    chain=open('ca.crt', 'rb').read()

    response = client.import_certificate(

        Certificate=certificate,

        PrivateKey=privatekey,

        CertificateChain=chain

    )

Ensure that your certificate files have the format mandated by ACM.

Want to learn more, enroll in our AWS training and also check our this AWS lambda tutorial.

Related questions

0 votes
1 answer
Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...