Closed matart15 closed 2 years ago
Thanks for opening the issue @matart15!
@yamatatsu any ideas? You know more about IoT than I do 🙂.
What's certificateSigningRequest: 'arn:aws:acm-pca:::template/RootCACertificate/V1'
? Is that some Amazon-owned Certificate Authority?
Hi all, I'm working on exactly the same thing right now. This is how I build my CSR value:
certificateSigningRequest: path.join( __dirname, "../../iot-certs/iot.com.csr"),
However, the violation can be more simply repeated, thus:
$ openssl genrsa -out key_name.key 4096
$ openssl req -out CSR.csr -key key_name.key -new -sha256
$ aws iot create-certificate-from-csr --certificate-signing-request=file:/CSR.csr
I have no issue when using the AWS GUI console. The CSR is accepted and a certificate is created.
Thanks
UPDATE: I missed a forward slash after file:/ This works now
$ aws iot create-certificate-from-csr --certificate-signing-request=file://CSR.csr
@skinny85
What's certificateSigningRequest: 'arn:aws:acm-pca:::template/RootCACertificate/V1'? Is that some Amazon-owned Certificate Authority?
No. I just did not know what value to input. I think I saw that on someone's cloud formation template
@brucegl
Thank you. I tried GUI : there is two options to create certificate.
Auto-generate. which gives me five file
use CSR. used CSR.csr
file output of your command. which gave me three files.
AmazonRootCA1.pem
AmazonRootCA3.pem
ddade268d08460c28dec5bb57cf29f2a21cf7203ffc28c4b1c5acc69b623195d.pem.crt
Now I don't know which file to use for which key
new iot.CfnCertificate(
this,
'IotCoreThingCertificate',
{
status: 'ACTIVE',
// certificateSigningRequest: path.join(__dirname, '../iot-certs/CSR.csr'),
caCertificatePem: path.join( __dirname, '/../iot_certs/AmazonRootCA1.pem'), // <----- which pem or crt file to use
certificatePem: path.join(__dirname, '/../iot_certs/AmazonRootCA3.pem'), // <----- which pem or crt file to use
},
);
I tried all possible combinations. they resulted Invalid request provided: The certificate is not valid.
@matart15 @brucegl
certificateSigningRequest
, caCertificatePem
and certificatePem
can take the content of file(key, cert ot csr) instead of path of file. So using fs.readFileSync()
is needed.
First, create csr:
mkdir cert
cd cert
openssl genrsa -out privatekey.pem 2048
openssl req -new -subj "/C=JP/ST=Tokyo/L=Chiyodaku/O=MyCompany/CN=AWS IoT Certificate" -key privatekey.pem -out cert.csr
Then you can use the cert with fs.readFileSync()
:
const iotCoreThingCertificate = new iot.CfnCertificate(
this,
"IotCoreThingCertificate",
{
status: "ACTIVE",
certificateSigningRequest: fs.readFileSync(
path.resolve("cert/cert.csr"),
"utf8"
),
}
);
@matart15
If you created the cert in web console, it is not needed to register the cert to IoT Core with CDK. Because the cert is already registered. Probably, You can see the cert and its ARN in web console. And you can use the ARN in CDK to attach to policies and things as principal
in step 4 and 5.
Just for reference, AWS provides an API that creates a key and a certificate at the same time (like you created them in web console), which can be used in CloudFormation custom resource. This repository may be helpful. https://github.com/devops-at-home/cdk-iot-core-certificates
I hope these help you!
@yamatatsu
I see. I am using web GUI just as a reference. My goal is to create everything by CDK code.
But your suggested code worked
I think my mistake was not using utf8
to read the file.
closing the issue. thank you again.
@matart15 and @yamatatsu thanks for the updates. This works for me too!
@yamatatsu thanks for the L3 construct tip - I'll circle back and check on what other L2 and L3 constructs I can use.
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Thanks so much for the help here @yamatatsu! You're a much better owner of IoT in CDK than I am 😃.
The previous construct has already been archived and is no longer functioning properly due to issues with the SDK version.
Therefore, I recommend using a different construct with an updated SDK version, which has now been released.
https://constructs.dev/packages/cdk-iot-core-certificates-v3
General Issue
https://ap-northeast-1.console.aws.amazon.com/iot/home?region=ap-northeast-1#/connectdevice/
The Question
When I start AWS: IOT, Get start page creates simple IoT thing, certificate, policy.
I want to create the same thing with CDK.
How to do that. I googled and looks like there is not much info.
As my understanding
To create IotThing
create certificate
create policy
connect thing and certificate
connect policy and certificate
on
2. create certificate
i get this error :Invalid request provided: CSR violates constraints
If I use commented code ( caCertificatePem + certificatePem ) :
Invalid request provided: No CA certificate exists for the given certificate
this is created YAML
Question :
The certificate signing request (CSR).
CertificateSigningRequest
?.CDK CLI Version
2.15.0 (build 151055e)
Framework Version
No response
Node.js Version
v14.18.3
OS
mac