Created
August 25, 2016 04:55
-
-
Save rayterrill/a7f2def3b1b2aafb09f96423b50c0472 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This builds out the base configuration for an IOT Thing + Certificate and Policy | |
$thingType = New-IOTThingType -ThingTypeName AdafruitWICEDFeather | |
$thing = New-IOTThing -ThingName WICEDFeatherA -ThingTypeName AdafruitWICEDFeather | |
$keysAndCert = New-IOTKeysAndCertificate | |
Update-IOTCertificate -CertificateId $keysAndCert.CertificateId -NewStatus Active | |
$policyDoc = @" | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": "iot:*", | |
"Resource": "*" | |
} | |
] | |
} | |
"@ | |
$policy = New-IOTPolicy -PolicyDocument $policyDoc -PolicyName WICEDFeatherA-Policy | |
Add-IOTThingPrincipal -ThingName $thing.ThingName -Principal $keysAndCert.CertificateArn | |
Add-IOTPrincipalPolicy -Principal $keysAndCert.CertificateArn -PolicyName $policy.PolicyName | |
$certBasename = $keysAndCert.CertificateId.Substring(0,10) | |
$publicKey = "$($certBasename)-public.pem.key" | |
$certificate = "$($certBasename)-certificate.pem.crt" | |
$privateKey = "$($certBasename)-private.pem.key" | |
#dump the files out for use on our device | |
$keysAndCert.KeyPair.PublicKey | Out-File $publicKey | |
$keysAndCert.KeyPair.PrivateKey | Out-File $privateKey | |
$keysAndCert.CertificatePem | Out-File $certificate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment