bitter-salesclerk-37287
11/16/2022, 8:43 PMlittle-cartoon-10569
11/16/2022, 8:43 PMbitter-salesclerk-37287
11/16/2022, 8:45 PMconst dynamodb = new DynamoDBClient({
region: DYNAMODB_REGION || '',
});
but I’m getting this error:
Diagnostics:
pulumi:pulumi:Stack (content-updater-prod):
error: Running program '/Users/riyad/repos/content-updater' failed with an unhandled exception:
Error: Region is missing
at resolveRegionConfig (/Users/riyad/repos/content-updater/node_modules/@dr-squatch/lib/node_modules/@aws-sdk/config-resolver/dist-cjs/regionConfig/resolveRegionConfig.js:9:15)
at new DynamoDBClient (/Users/riyad/repos/content-updater/node_modules/@dr-squatch/lib/node_modules/@aws-sdk/client-dynamodb/dist-cjs/DynamoDBClient.js:22:69)
at Object.<anonymous> (/Users/riyad/repos/content-updater/node_modules/@dr-squatch/lib/dist/aws/dynamodb.js:8:20)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/riyad/repos/content-updater/node_modules/@dr-squatch/lib/dist/aws/index.js:4:18)
… maybe I’m confused… maybe it is RT.
Just trying to be able to instantiate my dynamodb instance, and possibly other things, using my environment variables / configurations.little-cartoon-10569
11/16/2022, 8:47 PMconst awsConfig = new pulumi.Config("aws");
const region = awsConfig.require("region");
bitter-salesclerk-37287
11/16/2022, 8:48 PMlittle-cartoon-10569
11/16/2022, 8:49 PMconst config = new pulumi.Config();
const region = config.require("dynamoDbRegion");
bitter-salesclerk-37287
11/16/2022, 9:01 PMconst dynamodb = new DynamoDBClient({
region: DYNAMODB_REGION || '',
});
to work (esp from my npm installed dependency @dr-squatch/lib — which is currently private)… I also can’t comment out my dynamodb instantiation in my helper library, as I have other services (via Serverless Framework) successfully consuming that. If I move everything to devDependencies, my eslint complains, though I don’t exactly understand how that might work/help.little-cartoon-10569
11/16/2022, 9:03 PMbitter-salesclerk-37287
11/16/2022, 9:08 PMimport * as aws from '@pulumi/aws';
import * as pulumi from '@pulumi/pulumi';
import contentUpdater from './useCases';
const serviceName = 'content-updater';
const config = new pulumi.Config();
const envVars = config.requireObject('env');
const lambda = new aws.lambda.CallbackFunction(`${serviceName}-lambda`, {
policies: [aws.iam.ManagedPolicies.CloudWatchLogsFullAccess],
environment: {
variables: {
...envVars as any,
},
},
callback: contentUpdater,
});
I must be missing something simple here? I thought I had this working earlier, but potentially I suppose it’s possible that I may have modified something since then.little-cartoon-10569
11/16/2022, 9:09 PMmyproject:env:
key in your stack file? Is it an array?bitter-salesclerk-37287
11/16/2022, 9:11 PMdate; pulumi up -s prod; date
little-cartoon-10569
11/16/2022, 9:19 PMvariables: envVars as Record<string, string>
might also work..
What error are you getting right now?bitter-salesclerk-37287
11/16/2022, 11:12 PMlittle-cartoon-10569
11/16/2022, 11:46 PMbitter-salesclerk-37287
11/16/2022, 11:50 PMconst lambda = new aws.lambda.CallbackFunction(`${serviceName}-lambda`, {
policies: [aws.iam.ManagedPolicies.CloudWatchLogsFullAccess],
environment: {
variables: envVars as any,
},
callback: contentUpdater,
});
… I still have the error. What does this screenshot tell us? Is there some other way I’m supposed to be accessing the environment variables? It seems like all the values are there in Pulumi, so I don’t get what happens when I attempt to build the project (which is basically where I was originally today).little-cartoon-10569
11/17/2022, 12:11 AMenv
then look at it in a debugger / log statements, and compare that to what Function.environment.variables is expecting.
FWIW, in our projects that put Pulumi config values into lambda environments, we have this code. Don't know if it's needed, but I inherited this and didn't bother investigating it for efficiency:
const environmentVariables = new Array<KeyValuePair>();
const configEnvironmentVariables = pulumiConfig.getObject(
"environmentVariables",
) as Record<string, string>;
Object.entries(configEnvironmentVariables).forEach(([k, v]) => {
environmentVariables.push({ name: k, value: v.toString() });
});
The environmentVariables
variable is assigned directly to environment.variables.bitter-salesclerk-37287
11/17/2022, 12:12 AMlittle-cartoon-10569
11/17/2022, 12:13 AMbitter-salesclerk-37287
11/17/2022, 12:13 AMlittle-cartoon-10569
11/17/2022, 12:14 AMbitter-salesclerk-37287
11/17/2022, 12:14 AMpulumi up
run, but I was trying to do that earlier today, though.little-cartoon-10569
11/17/2022, 1:39 AMmyResource.apply((res) => <http://pulumi.log.info|pulumi.log.info>("My resource:", res));