-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IoT fleet provisioning event type #8324
Add IoT fleet provisioning event type #8324
Conversation
0387c72
to
5e34ae5
Compare
Codecov Report
@@ Coverage Diff @@
## master #8324 +/- ##
==========================================
+ Coverage 88.01% 88.05% +0.03%
==========================================
Files 249 250 +1
Lines 9307 9335 +28
==========================================
+ Hits 8192 8220 +28
Misses 1115 1115
Continue to review full report at Codecov.
|
5e34ae5
to
6043551
Compare
00bf3fc
to
8e49299
Compare
@medikoo my PR is ready for review when you have time. I made a small change from original plan, changing Unlike AWS::ApiGateway::Model Such JSON formatted string is quite painful to write. It either requires a yaml literal block and the whole template to be dumped as is in the functions:
provisioningYaml:
handler: 'handler.hello'
events:
- iotFleetProvisioning:
templateBody: |
{
"Parameters": {
"SerialNumber": {
"Type": "String"
},
"AWS::IoT::Certificate::Id": {
"Type": "String"
}
},
"Resources": {
"certificate": {
"Properties": {
"CertificateId": {
"Ref": "AWS::IoT::Certificate::Id"
},
"Status": "Active"
},
"Type": "AWS::IoT::Certificate"
},
"policy": {
"Properties": {
"PolicyName": "iotPolicy"
},
"Type": "AWS::IoT::Policy"
}
}
}
templateName: MyTemplateYaml
provisioningRoleArn: arn:aws:iam::123456789:role/test-provisioning or it requires content to be manually stringified : functions:
provisioningYaml:
handler: 'handler.hello'
events:
- iotFleetProvisioning:
templateBody: "{\"Parameters\":{\"SerialNumber\", ...}"
templateName: MyTemplateYaml
provisioningRoleArn: arn:aws:iam::123456789:role/test-provisioning Using an object, and serializing within the event compiler code allows much more fluent configuration : functions:
provisioningYaml:
handler: 'handler.hello'
events:
- iotFleetProvisioning:
templateBody: ${file(template.json)}
templateName: MyTemplateYaml
provisioningRoleArn: arn:aws:iam::123456789:role/test-provisioning WDYT ? |
5a99385
to
a2d077e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @fredericbarthelet That looks very promising! Please see my comments
Using an object, and serializing within the event compiler code allows much more fluent configuration
I totally agree! I believe we should definitely support just objects in such case
lib/plugins/aws/package/compile/events/iotFleetProvisioning/index.js
Outdated
Show resolved
Hide resolved
lib/plugins/aws/package/compile/events/iotFleetProvisioning/index.js
Outdated
Show resolved
Hide resolved
lib/plugins/aws/package/compile/events/iotFleetProvisioning/index.js
Outdated
Show resolved
Hide resolved
lib/plugins/aws/package/compile/events/iotFleetProvisioning/index.js
Outdated
Show resolved
Hide resolved
lib/plugins/aws/package/compile/events/iotFleetProvisioning/index.js
Outdated
Show resolved
Hide resolved
lib/plugins/aws/package/compile/events/iotFleetProvisioning/index.test.js
Outdated
Show resolved
Hide resolved
a2d077e
to
4d116ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fredericbarthelet thank you ! That looks great. I have just one cleanup suggestion towards the fixture.
Do you think it's possible to add integration test for it?
4d116ae
to
1d20a9c
Compare
@medikoo for sure, I will add those :) In order to test a device provisioning, IoT Core uses a public mqtt endpoint for me to publish to in order to initiate a Thing registration using the previously created provisioning template, and thus triggering the Pre-Provision lambda. In order to publish this message, my idea was to create a dedicated |
Yes, we already have some tests which require installing an extra dependencies, but so far it happens in a context of a Also for cases, where we need some extra infrastructure which is time taking to setup. We have dedicated infra cloudformation service, which is expected to be setup before tests that depend in infra are being run. Not sure if it's needed for this case, but it's good to be aware of such possibility. |
caf26c3
to
44b4496
Compare
@medikoo I'm a bit stuck with this feature integration test, and I would like your feedback on one of the 2 ways I see this coming through. I'm currently facing issues with the IoT sdk and opened the corresponding issue on their repo - aws/aws-iot-device-sdk-js-v2#100, but no response so far. This prevent me from simulating an IoT device within a lambda, making the required API interactions to register and use the new IoT fleet provisioning feature. The code is working fine when not executed within a lambda. Considering the situation, I could :
What's your opinion on that ? |
Are you bundling
If I see correctly However I would still keep it in a fixture. Fixtures engine have baked in support for setup logic. Simply create a |
I'm bundling, see
Here is small schema of a real life scenario I'm trying to reproduce through the integration test to make it clearer :
There are no requirement for initial test logic setup, everything is already included within the My question was wether I could move 3, 4 and 5 from @medikoo , is it more clear ? |
@fredericbarthelet I understand that in real world scenarios, the logic that currently part of If that's the case I would keep the things the way you prepared initially. Concerning issue you reported here aws/aws-iot-device-sdk-js-v2#100. async/await is a core language construct, and I don't think it's possible for it to work differently in lambda context. From what you describe it appears that there's some network or lambda setup issue. If |
I agree, however I see a difference which is currently driving me crazy ^^ In const resp = await awsRequest('Lambda', 'invoke', {
FunctionName: `${stackName}-registerDevice`,
InvocationType: 'RequestResponse',
Payload: JSON.stringify(certificates),
}); or doing a direct code execution with const { registerDevice } = require('../fixtures/iotFleetProvisioning/index');
const resp = await registerDevice(certificates); does NOT result in the same output. @medikoo do you see something obvious I'm missing out ? I'll continue on working on my test implementing the latter |
82ed823
to
c29b5c1
Compare
Codecov Report
@@ Coverage Diff @@
## master #8324 +/- ##
==========================================
+ Coverage 87.25% 87.29% +0.03%
==========================================
Files 255 256 +1
Lines 9614 9642 +28
==========================================
+ Hits 8389 8417 +28
Misses 1225 1225
Continue to review full report at Codecov.
|
…eetProvisioning fixtures package installation
498d946
to
1ffa428
Compare
Alright, thanks @medikoo for the explanation. I updated the comments as you suggested :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @fredericbarthelet !
Closes: #8296