Error re-bootstrapping in AWS CDK: "Public key und...
# support
c
I found this other bug that has the same error, but I don't understand the fix and would appreciate help. https://discord.com/channels/905144809105260605/1206826738835922974 Have re-created fresh repo, deleted old "public keys" in IAM and KMS (scheduled deletion of customer managed keys), reconfigured aws in CLI, but cannot bootstrap successfully, after it working the first time. Any help appreciated
Copy code
npx cdk bootstrap -c config=medplum.dev.config.json
Error: Public key must be in PEM format (with the BEGIN/END PUBLIC KEY lines); got undefined
    at new PublicKey (/Users/mac/Desktop/Claimant Meta/medplum-cdk-config/node_modules/@medplum/cdk/node_modules/aws-cdk-lib/aws-cloudfront/lib/public-key.js:1:1024)
    at new L (/Users/mac/Desktop/Claimant Meta/medplum-cdk-config/node_modules/@medplum/cdk/dist/cjs/index.cjs:1:80062)
    at new H (/Users/mac/Desktop/Claimant Meta/medplum-cdk-config/node_modules/@medplum/cdk/dist/cjs/index.cjs:1:83002)
    at new B (/Users/mac/Desktop/Claimant Meta/medplum-cdk-config/node_modules/@medplum/cdk/dist/cjs/index.cjs:1:82648)
    at /Users/mac/Desktop/Claimant Meta/medplum-cdk-config/node_modules/@medplum/cdk/dist/cjs/index.cjs:1:83629
@ayushaadijain i know you've encountered this bug, if you could explain a bit further would appreciate it
r
To be clear, @casualgardener , you regenerated the public key after deleting it, and can look at it with your human eyes and see that it starts with
-----BEGIN PUBLIC KEY-----
?
(Not to be the "is it plugged in?" person, I just know that it's easy, when repeating a long sequence of instructions, to misremember having done it the first time as having done it the nth time)
c
hmm you're right
For anyone else, the resolution is to delete the public key in CloudFront => Key Management => Public Keys, then re initialize the project (it's ok to do this in the same repo/project folder and overwrite the config)
this config step may have been somewhere in the docs or video, but i couldn't find it - maybe a useful clarification for the docs, maybe more experienced AWS/infra devs will understand this readily
r
Thanks @casualgardener - glard you were able to get this resolved!
Thank you @rebeccalovering for the support!
s
I've ran into the exact same issue and the solution does not make sense to me. If cdk bootstrap fails to read the content of an existing public key, why would deleting it fix the issue? As described in this topic, I am also re-deploying medplum on AWS. I made sure I had no public keys in AWS CloudFront before running
npx medplum aws init
, and afterwards checked that a new public key was created which started with
-----BEGIN PUBLIC KEY-----
. After running the next step
npx cdk bootstrap -c config=...
I received the error
Public key must be in PEM format (with the BEGIN/END PUBLIC KEY lines); got undefined
, same as in this topic. I tried following the suggested solution and deleting the key, but am still receiving the same error. I have also restored the key with the key-content I copied and saved previously, but the error does not change. @casualgardener What did you do after deleting your public key from CloudFront?
c
The difference i found was that when i re ran npx medplum init, it generated a new public key
I tried a few other things that may have contributed like recreating the repo
I mistakenly said "when i reran bootstrap" - i had to re init the project after deleting the public key
i simply re init'd and overwrote the config, then bootstrapped
let me know if that works
s
The error
Public key must be in PEM format (with the BEGIN/END PUBLIC KEY lines); got undefined
had nothing to do with the public key in CloudFront (at least in my case). Instead something went wrong during the execution of
npx medplum aws init
and the following 3 parameters were missing in Systems Manager -> Parameter Store:
/medplum/<environment_name>/signingKey
/medplum/<environment_name>/signingKeyId
/medplum/<environment_name>/signingKeyPassphrase
I managed to solve this issue by deleting the public key, parameters and medplum..config.json and then rerunning
npx medplum aws init
. I had to execute this process twice before all necessary parameters were generated (the parameter list can be seen in the video guide:

https://youtu.be/_YCYbgb63Y0?feature=shared&t=647▾

).
327 Views