aqi-notifier-lambda-cdk
is an L3 AWS CDK construct. It creates a Lambda function to send
an AQI score for a specified zipcode. It leverages the AirNow API and Twilio SMS for functionality.
npm i aqi-notifier-lambda-cdk
There are two ways to instantiate the Lambda, which provide flexibility for different situations.
This will configure the application via environment variables. This can be handy for some proof of concept work. Of course, you don't want to store secrets in source control. Creating the construct with empty strings for keys will still allow you to set the values in the console, however, deploying the construct will eliminate any drift in the values.
import * as cdk from '@aws-cdk/core';
import { EnvLambda } from 'aqi-notifier-lambda-cdk';
export class CdkTestHarnessStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new EnvLambda(this, 'AqiNotifier', {
openAirApiKey: '',
toPhoneNumber: '+11234567890',
twilioAccountSid: '1234567890abcdefghijklmn1234567890',
twilioAuthToken: '',
twilioFromPhoneNumber: '+11234567890',
zipCode: '97216',
});
}
}
This configuration will use AWS SSM Parameter store for general configuration, and Secrets Manager for sensitive info.
The CDK Construct cannot set the SecretString
value
, but you can set this afterwards, in a secure process. The paramAndSecretRoot
property allows for namespacing secrets, to keep instantiations independent.
import * as cdk from '@aws-cdk/core';
import { AwsConfigLambda } from 'aqi-notifier-lambda-cdk';
export class CdkTestHarnessStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new AwsConfigLambda(this, 'AqiNotifier', {
paramAndSecretRoot: '/aqi-lambda',
openAirApiKey: '',
toPhoneNumber: '+11234567890',
twilioAccountSid: '1234567890abcdefghijklmn1234567890',
twilioAuthToken: '',
twilioFromPhoneNumber: '+11234567890',
zipCode: '97216',
});
}
}