-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into amplify-cache-config
- Loading branch information
Showing
17 changed files
with
840 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"exclude": [ | ||
"no-unused-type:@aws-cdk/aws-iot-alpha.ActionConfig" | ||
"no-unused-type:@aws-cdk/aws-iot-alpha.ActionConfig", | ||
"props-physical-name:@aws-cdk/aws-iot-alpha.LoggingProps" | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './action'; | ||
export * from './iot-sql'; | ||
export * from './logging'; | ||
export * from './topic-rule'; | ||
|
||
// AWS::IoT CloudFormation Resources: |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { Resource, Stack, IResource } from 'aws-cdk-lib/core'; | ||
import { Construct } from 'constructs'; | ||
import * as iot from 'aws-cdk-lib/aws-iot'; | ||
import * as iam from 'aws-cdk-lib/aws-iam'; | ||
|
||
/** | ||
* Represents AWS IoT Logging | ||
*/ | ||
export interface ILogging extends IResource { | ||
/** | ||
* The log ID | ||
* @attribute | ||
*/ | ||
readonly logId: string; | ||
} | ||
|
||
/** | ||
* The log level for the AWS IoT Logging | ||
*/ | ||
export enum LogLevel { | ||
/** | ||
* Any error that causes an operation to fail | ||
* | ||
* Logs include ERROR information only | ||
*/ | ||
ERROR = 'ERROR', | ||
|
||
/** | ||
* Anything that can potentially cause inconsistencies in the system, but might not cause the operation to fail | ||
* | ||
* Logs include ERROR and WARN information | ||
*/ | ||
WARN = 'WARN', | ||
|
||
/** | ||
* High-level information about the flow of things | ||
* | ||
* Logs include INFO, ERROR, and WARN information | ||
*/ | ||
INFO = 'INFO', | ||
|
||
/** | ||
* Information that might be helpful when debugging a problem | ||
* | ||
* Logs include DEBUG, INFO, ERROR, and WARN information | ||
*/ | ||
DEBUG = 'DEBUG', | ||
|
||
/** | ||
* All logging is disabled | ||
*/ | ||
DISABLED = 'DISABLED', | ||
} | ||
|
||
/** | ||
* Properties for defining AWS IoT Logging | ||
*/ | ||
export interface LoggingProps { | ||
/** | ||
* The log level for the AWS IoT Logging | ||
* | ||
* @default LogLevel.ERROR | ||
*/ | ||
readonly logLevel?: LogLevel; | ||
} | ||
|
||
/** | ||
* Defines AWS IoT Logging | ||
*/ | ||
export class Logging extends Resource implements ILogging { | ||
/** | ||
* Import an existing AWS IoT Logging | ||
* | ||
* @param scope The parent creating construct (usually `this`) | ||
* @param id The construct's name | ||
* @param logId AWS IoT Logging ID | ||
*/ | ||
public static fromLogId(scope: Construct, id: string, logId: string): ILogging { | ||
class Import extends Resource implements ILogging { | ||
public readonly logId = logId; | ||
} | ||
return new Import(scope, id); | ||
} | ||
|
||
/** | ||
* The logging ID | ||
* @attribute | ||
*/ | ||
public readonly logId: string; | ||
|
||
constructor(scope: Construct, id: string, props?: LoggingProps) { | ||
super(scope, id); | ||
|
||
const accountId = Stack.of(this).account; | ||
|
||
// Create a role for logging | ||
// https://docs.aws.amazon.com/iot/latest/developerguide/configure-logging.html#configure-logging-role-and-policy | ||
const role = new iam.Role(this, 'Role', { | ||
assumedBy: new iam.ServicePrincipal('iot.amazonaws.com'), | ||
inlinePolicies: { | ||
LoggingPolicy: new iam.PolicyDocument({ | ||
statements: [ | ||
new iam.PolicyStatement({ | ||
actions: [ | ||
'logs:CreateLogGroup', | ||
'logs:CreateLogStream', | ||
'logs:PutLogEvents', | ||
'logs:PutMetricFilter', | ||
'logs:PutRetentionPolicy', | ||
'iot:GetLoggingOptions', | ||
'iot:SetLoggingOptions', | ||
'iot:SetV2LoggingOptions', | ||
'iot:GetV2LoggingOptions', | ||
'iot:SetV2LoggingLevel', | ||
'iot:ListV2LoggingLevels', | ||
'iot:DeleteV2LoggingLevel', | ||
], | ||
resources: [ | ||
Stack.of(this).formatArn({ | ||
service: 'logs', | ||
resource: 'log-group', | ||
sep: ':', | ||
resourceName: 'AWSIotLogsV2:*', | ||
}), | ||
], | ||
}), | ||
], | ||
}), | ||
}, | ||
}); | ||
|
||
const resource = new iot.CfnLogging(this, 'Resource', { | ||
accountId, | ||
defaultLogLevel: props?.logLevel ?? LogLevel.ERROR, | ||
roleArn: role.roleArn, | ||
}); | ||
|
||
this.logId = resource.ref; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../test/integ.logging.js.snapshot/IotLoggingTestDefaultTestDeployAssertB1DE3CEF.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...est/integ.logging.js.snapshot/IotLoggingTestDefaultTestDeployAssertB1DE3CEF.template.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
...ges/@aws-cdk/aws-iot-alpha/test/integ.logging.js.snapshot/IotLoggingTestStack.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.