Thursday, November 14, 2024

AWS CDK Get Parameter Store Value

Problem:

There are multiple ways to get a parameter store value. Which one should I use?

Solution:

Use this approach when working with non-sensitive, plain text parameters. You don't need 
version control and simple string value retrieval is sufficient. Creates a "token" that resolves during deployment.

const value = ssm.StringParameter.valueForStringParameter(this, 'my-parameter-name');

Use this approach when handling secure string parameters. Creates a secure "token" that resolves during deployment.

const value = cdk.SecretValue.ssmParameter('my-parameter-name');

Use this syntax when you need a fixed, environment-specific value at synthesis time instead of at deployment. This retrieves the actual SSM parameter value during cdk synth and stores it in the cdk.context.json file. Use this approach when conditional logic in your CDK code requires the value and cannot use a token. For example, determining which resources to synthesize based on a feature flag

const value = ssm.StringParameter.valueFromLookup(this, 'my-parameter-name');

https://docs.aws.amazon.com/cdk/v2/guide/get_ssm_value.html

Monday, October 7, 2024

AWS CDK Set CloudFormation Property Escape Hatch

 Problem:

The CDK does not always support all CloudFormation properties. A super simple escape hatch is to use  a addOverride one-liner. There are more robust escape hatches but this is super simple especially for deeply nested properties. Ideally, these are temporary until the CDK exposes properties directly.

Solution:

// The CDK does not currently support dynamic wildcard branch names (and other GitHub version 2 properties) but CloudFormation does.
const cfnPipeline = pipeline.node.defaultChild as codepipeline.CfnPipeline;
cfnPipeline.addOverride('Properties.Stages.0.Actions.0.Configuration.BranchName', `*-${env}-*`);

Wednesday, June 26, 2024

AWS CDK Chart.js Canvas Layer for AWS Lambda

 Problem:

Using the AWS CDK v2, how to deploy the "Canvas Layer for AWS Lambda" serverless application and attach the layer to a Lambda function.

lambda-layer-canvas-nodejs

https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs

https://charoitel.github.io/lambda-layer-canvas-nodejs/

To get the latest semanticVersion:

  1. Open the AWS Management Console.
  2. Navigate to the Serverless Application Repository.
  3. Search for lambda-layer-canvas-nodejs.
  4. View the application details to find the latest version.

Solution:

import { Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { CfnApplication } from 'aws-cdk-lib/aws-sam';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as lambdaNJS from 'aws-cdk-lib/aws-lambda-nodejs';

export default class ChartStack extends Stack {
    constructor(scope: Construct, id: string, props: cdk.StackProps) {
        super(scope, id, props);

        const chartJsApp = new CfnApplication(this, 'ChartJsApp', {
            location: {
                applicationId: 'arn:aws:serverlessrepo:us-east-1:990551184979:applications/lambda-layer-canvas-nodejs',
                semanticVersion: '2.11.3'
            }
        });

        const layerArn = chartJsApp.getAtt('Outputs.LayerVersion').toString();

        const njs = new lambdaNJS.NodejsFunction(this, 'ChartLambda', {
            entry: 'main.ts',
            handler: 'handler',
            runtime: lambda.Runtime.NODEJS_18_X,
            layers: [lambda.LayerVersion.fromLayerVersionArn(this, 'ChartJsLayer', layerArn)]
        });

        // Add dependency to ensure the layer is deployed before the function
        njs.node.addDependency(chartJsApp);
    }
}

Tuesday, May 28, 2024

AWS CDK V2 Synth Error when Bundling a NodejsFunction

 Problem:
AWS CDK version 2 synth error when bundling a NodejsFunction with somewhat complicated Typescript source code.

Error:
RangeError: Maximum call stack size exceeded

Solution:
Upgrade to a more recent version of npm package "esbuild". In this case, upgrading to version 0.19.12 resolve the issue even though this isn't the most recent version available. Other third party npm package constraints did not allow the latest version to be installed. npm i -D esbuild@0.19.12


Friday, May 3, 2024

AWS Lambda Typescript Ends Unexpectedly

 Problem:

An AWS Lambda in TypeScript ends unexpectedly with a CloudWatch success message (i.e. no errors logged).

Solution:

a. Increase Lambda memory size if low.

b. Check for missing await. Various console.log statements might log to CloudWatch but Lambda does not run to completion.

Wednesday, March 20, 2024

Developer Setup on Windows

Windows

  1. Display settings.

Install 

  1. Google Chrome
    • Make default browser
    • Plugins:
      • AWS Extend Switch Roles
      • Bitwarden
      • Session Buddy
  2. Firefox + Edge + Brave
  3. NVidia GeForce Experience (use to download latest drivers)
  4. Git for Windows
  5. TortoiseGit
    • git config --global --add safe.directory 'c:/myfolder'
    • github will prompt to login via browser
  6. Visual Studio Code
  7. Node.js includes npm
  8. AWS CLI
  9. MySQL Workbench
  10. Notepad++
  11. Draw.io
  12. SnagIt
  13. Camtasia
  14. MS office + teams + skype
    •  Configure Outlook to open links in default browser.
  15. Open OneDrive and login to accounts to view files on local
  16. Adobe Acrobat Reader
NPM
  • npm install -g @ionic/cli
  • npm install -g @angular/cli
Visual Studio Code
  • Command Palette > Open User Settings JSON
    {
        "typescript.implementationsCodeLens.enabled": true,
        "[typescript]": {
            "editor.detectIndentation": false,
            "editor.tabSize": 4,
        },
        "[html]": {
            "editor.detectIndentation": false,
            "editor.tabSize": 4
        }
    }

Troubleshooting
  • speedtest.net (internet connection speed test)
  • 3DMark demo (for basic GPU/CPU benchmark)

Friday, March 8, 2024

SuperMicro Desktop Workstation Build 2024

Supermicro Full-Tower SuperWorkstation (SYS-551A-T)

CPU
1 x Intel® Xeon® W5-3435X Processor 16-Core 3.10 GHz 45MB Cache (270W) 

Memory
2 x 32GB DDR5 4800MHz ECC RDIMM Server Memory 

Storage
1 x 1.9TB 2.5" 7450 PRO NVMe (7mm) PCIe 4.0 Solid State Drive (1 x DWPD) 

Networking
1 x 1 x 10Gb E
 
GPU
1 x NVIDIA Quadro RTX A4000 16GB GDDR6 PCIe 4.0 x16 - 4 DisplayPort (140W) 

Accessory
1 x MCP-220-73102-0N - 3.5" to 2.5" Converter Drive Tray (Required Accessory)
1 x MiniSAS HD to U.3 with Power Cable (Required Accessory) 
1 x CBL-0082L - Y Split SATA Power Adapter (Required Accessory)
1 x CBL-SAST-0624 - SATA 70cm Cable (Required Accessory)
1 x DVM-TEAC-DVDRW24-HBT - Slim DVD-RW SATA Drive (Required Accessory)
1 x SKT-1333L-0000-FXC - E1A Carrier (Required Accessory)
1 x SNK-P0091AP4 - 4U Active CPU Heat Sink (Required Accessory)
1 x FAN-0222L4 - 120MM Fan (Required Accessory)

Operating System
1 x Windows 11 Professional 64-Bit

Display
2 x Acer Predator XB273K Pbmiphzx 27" UHD (3840 x 2160) IPS Monitor with NVIDIA G-SYNC

I/O Ports

Front:

    • two USB2.0 ports
    • two USB3.2 Gen1 (5 G) Type A ports
    • one USB3.2 Gen2 (10 G) Type C port
    • one Power Button
    • one Audio In, one Mic In

Button Rear:

    • one 10 Gb LAN port
    • one 1Gb LAN port
    • one USB3.2 Gen2 x2 (20 Gbps) Type C port
    • four USB3.2 Gen2 x1 ports
    • two USB2.0 ports
    • one VGA port (for BMC interface)
    • HD Audio 7.1 Channel connectors
    • one COM port

Onboard:

    • one USB3.2 Gen 2 Type C header
    • two USB3.2 Gen1 (5 G) headers
    • two USB2.0 headers
    • ten 4-pin fan headers
    • one 1 2V power header for water cooling pump
    • one DOM PW connector
    • one TPM 2.0 header

SuperWorkstation SYS-551A-T
SYS-551A-T Manual

Problem 1:
Displays message "checking media presence" and displays the BIOS page.
Support Wrote:
press F11 to the boot menu. It should have the "UEFI: Windows OS" option. Check the U.2 drive cable inside the chassis.  Make sure that the cable was connected properly on both U.2 connector and U.2 drive. 
Solution 1:
The cable was not plugged into the back of the system drive located in one of the drive bays. Simply plugging the cable in resolved this issue. The cabling bundle tie is too tight. It needs to be cut to give the cables more slack.

Problem 2:
Windows 11 is not activated.
Solution 2:
Bottom of chassis contains a Windows sticker. Lightly scratch the silver part to reveal the rest of the 25 character Windows activation code. Settings > Activation settings > Change product key (enter key from sticker).

Problem 3:
Windows 11 is so slow it's basically unusable. e.g. File explorer takes 10 secs to display completely.
Solution 3:
Set: Control Panel > Power Options > High Performance

Problem 4:
Windows 11, "system > display" shows 3 monitors. One of them is labelled "1" and is a phantom (i.e. this physical monitor doesn't exist). Clicking "disconnect this display" does not fix the problem.
Solution 4:
?