in aws/iot.go [189:216]
func CreateAndAttachRoleAliasPolicy(client IotClient, roleAliasArn *string, certArn *string, iotThingName *string) {
policyDocument := `{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "iot:AssumeRoleWithCertificate",
"Resource": "%s"
}
}`
policyDocument = fmt.Sprintf(policyDocument, *roleAliasArn)
now := time.Now()
policyName := fmt.Sprintf("aliaspolicy-%d", now.UTC().Unix())
if _, err := client.CreatePolicy(context.TODO(), &iot.CreatePolicyInput{
PolicyName: &policyName,
PolicyDocument: &policyDocument,
}); err != nil {
log.Fatalf("Failed to cerate iot policy %s. Encountered error %s\n", policyName, err)
}
if _, err := client.AttachPolicy(context.TODO(), &iot.AttachPolicyInput{
PolicyName: &policyName,
Target: certArn,
}); err != nil {
log.Fatalf("Failed to attach iot policy %s. Encountered error %s\n", policyName, err)
}
}