Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alinadima committed May 9, 2023
1 parent 14caff4 commit 5f37c0f
Show file tree
Hide file tree
Showing 17 changed files with 7,878 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/.idea/
# Ignore Mac DS_Store files
**/.DS_Store
/test-app/node_modules/
/node_modules/
/cdk-iot-sample.iml
/cdk.out/
/test-app/MyIoTThing.cert.pem
/test-app/MyIoTThing.private.key
57 changes: 49 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
## My Project

TODO: Fill this README out!

Be sure to:

* Change the title in this README
* Edit your repository description on GitHub
# CDK IoT Sample Project

This is a sample project which shows how to create, deploy and start a simple Node.js IoT application.
The code in this sample project was written by using the AI companionship of Amazon CodeWhisperer.
The comments in the code show what Amazon CodeWhisperer was 'told' to generate.

The project is composed of two parts:

1. The Typescript CDK infrastructure as code, which creates the needed resources as follows:
- An IoT policy,
- An IoT Rule,
- An AWS Lambda function which is invoked as a Rule Action.
The `cdk.json` file tells the CDK Toolkit how to execute your app.

2. A Javascript application, which:
- Creates an AWS IoT Thing,
- Creates the needed IoT thing identity (certificate and keys),
- Attaches the policy to the certificate, and the certificate to the thing,
- Creates an MQTT client using the MQTT.JS open source library,
- Starts the MQTT client, connects to AWS IoT Core,
- Subscribes and publishes data on interval on an MQTT topic.

## Pre-Requisites
* To be able to deploy the CDK resources, as well as run your application, you need to:
* Ensure you provide the scripts the needed AWS credentials.
* Replace the `ENDPOINT`value with your AWS Account and REGION IoT Endpoint in line 11 in [here](test-app/app.js).

## Useful commands

* To prepare and deploy the AWS resources created using CDK:

* `npm install` install dependencies as node modules
* `npm run build` compile typescript to js
* `npm run watch` watch for changes and compile
* `npm run test` perform the jest unit tests
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk synth` emits the synthesized CloudFormation template

* To run the Javascript application:
* `npm install` install dependencies as node modules
* `node test-app/app.js` run JavaScript app

## Clean-up steps
* Clean up your app-created resources, certificates, thing etc.
* `node test-app/clean-up-app.js` run JavaScript app

* Clean up your CDK created resources:
* `cdk destroy` delete resources from your AWS Account

## Security

Expand Down
2 changes: 2 additions & 0 deletions bin/cdk_io_t.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
import 'source-map-support/register';
20 changes: 20 additions & 0 deletions bin/cdk_io_t.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions bin/cdk_io_t.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import { CdkIoTStack } from '../lib/cdk_io_t-stack';

const app = new cdk.App();
new CdkIoTStack(app, 'CdkIoTStack', {
/* If you don't specify 'env', this stack will be environment-agnostic.
* Account/Region-dependent features and context lookups will not work,
* but a single synthesized template can be deployed anywhere. */

/* Uncomment the next line to specialize this stack for the AWS Account
* and Region that are implied by the current CLI configuration. */
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },

/* Uncomment the next line if you know exactly what Account and Region you
* want to deploy the stack to. */
// env: { account: '123456789012', region: 'us-east-1' },

/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
});
5 changes: 5 additions & 0 deletions cdk.context.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"acknowledged-issue-numbers": [
19836
]
}
53 changes: 53 additions & 0 deletions cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"app": "npx ts-node --prefer-ts-exts bin/cdk_io_t.ts",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"tsconfig.json",
"package*.json",
"yarn.lock",
"node_modules",
"test"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true
}
}
5 changes: 5 additions & 0 deletions lib/cdk_io_t-stack.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as cdk from '@aws-cdk/core';
import { Construct } from "@aws-cdk/core";
export declare class CdkIoTStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps);
}
Loading

0 comments on commit 5f37c0f

Please sign in to comment.