Aman Saran
01/03/2022, 10:27 PMRoberto Novelo
01/04/2022, 3:06 AMUserPool.userPoolId
from @aws-cdk/aws-cognito)
at build time?
The CDK code I have right now only works because I am deploying the next.js site separately from the cdk backend, using the outputs json file generated from the outputs flag.
P.D. Thanks to the SST team for the wonderful tool! I really think SST is the way!Garret Harp
01/04/2022, 5:41 AMMarcin M
01/04/2022, 10:29 AMconst submitLambda = new Function(this, "SubmitLambda", {
handler: "src/placeOrder/lambdas.submit",
});;
const getStatusLambda = new Function(this, "getStatusLambda", {
handler: "src/placeOrder/lambdas.getStatus",
});;;
const submitJob = new tasks.LambdaInvoke(this, 'Submit Job', {
lambdaFunction: submitLambda,
// Lambda's result is in the attribute `Payload`
outputPath: '$.Payload',
});
const waitX = new sfn.Wait(this, 'Wait X Seconds', {
time: sfn.WaitTime.secondsPath('$.waitSeconds'),
});
const getStatus = new tasks.LambdaInvoke(this, 'Get Job Status', {
lambdaFunction: getStatusLambda,
// Pass just the field named "guid" into the Lambda, put the
// Lambda's result in a field called "status" in the response
inputPath: '$.guid',
outputPath: '$.Payload',
});
const jobFailed = new sfn.Fail(this, 'Job Failed', {
cause: 'AWS Batch Job Failed',
error: 'DescribeJob returned FAILED',
});
const finalStatus = new tasks.LambdaInvoke(this, 'Get Final Job Status', {
lambdaFunction: getStatusLambda,
// Use "guid" field as input
inputPath: '$.guid',
outputPath: '$.Payload',
});
const definition = submitJob
.next(waitX)
.next(getStatus)
.next(new sfn.Choice(this, 'Job Complete?')
// Look at the "status" field
.when(sfn.Condition.stringEquals('$.status', 'FAILED'), jobFailed)
.when(sfn.Condition.stringEquals('$.status', 'SUCCEEDED'), finalStatus)
.otherwise(waitX));
new sfn.StateMachine(this, 'StateMachine', {
definition,
timeout: Duration.minutes(5),
});
it does work, the stateMachine is being deployed to the AWS, i can run it (from AWS) and I see that the exection is correct only if the guid is numeric. those are my lambdas:
export async function submit(event:any) {
console.log("sumbit Lambda", event);
const response = {
statusCode: 200,
headers: { "Content-Type": "text/plain" },
body: `Hello, World! Are we running locally: ${!!process.env.IS_LOCAL}`,
waitSeconds: 1,
guid: '3',
};
return response;
}
export async function getStatus(event:any) {
const status = Math.random() >= 0.5 ? "FAILED" : "SUCCEEDED";
console.log("getStatys Lambda", event, status);
return {
statusCode: 200,
headers: { "Content-Type": "text/plain" },
body: `Hello, World! Are we running locally: ${!!process.env.IS_LOCAL}`,
status: status,
guid: '3',
};
}
and it does work. but if I change the submit lambda to:
export async function submit(event:any) {
console.log("sumbit Lambda", event);
const response = {
statusCode: 200,
headers: { "Content-Type": "text/plain" },
body: `Hello, World! Are we running locally: ${!!process.env.IS_LOCAL}`,
waitSeconds: 1,
guid: 'abc',
};
return response;
}
the difference is guid: 'abc' vs guid: '3'.
I get the following error on the getStatus state
{
"error": "Lambda.InvalidRequestContentException",
"cause": "Could not parse request body into json: Could not parse payload into json: Unrecognized token 'abc': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (byte[])\"abc\"; line: 1, column: 4] (Service: AWSLambda; Status Code: 400; Error Code: InvalidRequestContentException; Request ID: 7291da41-1c65-441b-8778-c87602b922cf; Proxy: null)"
}
any idea what may be wrong? I tried different ways of forming the string and all failed which drives me crazy. :DDaniel Gato
01/04/2022, 11:52 AM.vscode/settings.json
in the root folder with this:
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"],
}
But this is still not converting ' to ” (or the other way) and my tabs are still not formatted. What am I missing here?Mischa Spiegelmock
01/04/2022, 2:06 PMError: There was a problem transpiling the Lambda handler: file:///Users/cyber/dev/jb/platform/packages/infra/.sst/artifacts/979b4130/builder.js:2
const esbuild = require("esbuild")
^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/Users/cyber/dev/jb/platform/packages/infra/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///Users/cyber/dev/jb/platform/packages/infra/.sst/artifacts/979b4130/builder.js:2:25
at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
Trying to maintain this patch but it's not going great. I think I need to write package.json out to the .sst
dir? Where do I get that path? What do we need to do to get this merged?Paul
01/04/2022, 4:44 PMSeth Geoghegan
01/04/2022, 5:55 PMdev
stage
and prod
, all are meant to be long-lived. The API has long lived stages stage
and prod
with an ephemeral local environment named after the person doing the development (e.g. sst start --stage {whoami}
) I want the ephemeral API environment to use the dev
RDS instance. The same problem applies to any long-lived resources (RDS, ElasticSearch, VPN's, EventBridge, Route53, etc).
I tried and tried to get this working within the same SST app by conditionally creating resources depending on app.stage
, but it felt forced and error proned. I read The CDK Book looking for clues of useful patterns, but I didn't find what I was looking for.
For now, I've created two SST apps; one for the RDS Instance and the other for the API. This feels much more natural, but I'm wondering if I'm "Doing It Right™️"?Jared Burke
01/04/2022, 7:18 PMApolloAPI
I need to add a copyFiles
prop to the bundle. This works when running sst build
-- my files are correctly copied to the output directory. But when I run sst start
, the copyFiles
doesn't seem to be respected, and in fact clears out those files that were copiedRoberto Novelo
01/04/2022, 9:16 PMA version for this Lambda function exists ( 1 ). Modify the function to create a new version.
on a stack using Cognito, SSM and Next.js. It seems like ApiFunctionCurrentVersion
ImageFunctionCurrentVersion
are failing to create and and MainFunction
is failing to update. Could this mean something’s wrong with my constructs? I also added "@aws-cdk/aws-lambda:recognizeVersionProps": true
to my cdk.contect.json
.Dan Russell
01/04/2022, 11:38 PMTony J
01/04/2022, 11:50 PMGarret Harp
01/05/2022, 1:39 AMCarlos Daniel
01/05/2022, 1:51 AMJeff Cordova
01/05/2022, 6:28 AMnpx create-serverless-stack@latest notes
cd notes
npx sst start
Then I get this error:
/.../Serverless/my-sst-app/node_modules/@aws-cdk/core/lib/stack.js:78
throw new Error(`Stack name must match the regular expression: ${VALID_STACK_NAME_REGEX.toString()}, got '${this.stackName}'`);
^
Error: Stack name must match the regular expression: /^[A-Za-z][A-Za-z0-9-]*$/, got '1dmg-my-sst-app-debug-stack'
at new Stack (.../Desktop/Serverless/my-sst-app/node_modules/@aws-cdk/core/lib/stack.js:78:19)
at new DebugStack (/.../Serverless/my-sst-app/node_modules/@serverless-stack/cli/assets/debug-stack/lib/DebugStack.js:11:5)
at Object.<anonymous> (/.../Serverless/my-sst-app/node_modules/@serverless-stack/cli/assets/debug-stack/bin/index.js:25:15)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
There was an error synthesizing your app.
Daniel Gato
01/05/2022, 8:47 AMSecuring React Pages
I tried to logout/login to see if it works and I can’t log back in. I have this message:
QuotaExceededError: The quota has been exceeded.I’m using Safari and when I hit
cmd
+ options
+ r
, I can then login again.Edward Asquith
01/05/2022, 12:39 PMrequire(…)
problem.
Seems like it’s probably a bundling problem specific to sst or esbuild, and it’s beyond my skill-set so far… so any help would be awesome.
I have some code running in a lambda configured using the sst.Queue
construct. It is calling a library that uses proxy-agent
under the hood, loaded via require('proxy-agent');
. This library has a transitive dependency on vm2
(to run the PAC file, I assume).
When run with unit tests, this library call runs fine. When run under npx sst start
, the require
call fails like this:
Error: ENOENT: no such file or directory, open '/Users/asquithea/repos/deploy-controller/.sst/artifacts/aff14e6d/src/handlers/contextify.js'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at loadAndCompileScript (/Users/asquithea/repos/deploy-controller/node_modules/vm2/lib/main.js:49:18)
at node_modules/vm2/lib/main.js (/Users/asquithea/repos/deploy-controller/node_modules/vm2/lib/main.js:76:20)
at __require (/Users/asquithea/repos/deploy-controller/.sst/artifacts/aff14e6d/src/handlers/command.js:26:44)
at node_modules/vm2/index.js (/Users/asquithea/repos/deploy-controller/node_modules/vm2/index.js:3:18)
at __require (/Users/asquithea/repos/deploy-controller/.sst/artifacts/aff14e6d/src/handlers/command.js:26:44)
at node_modules/degenerator/dist/src/index.js (/Users/asquithea/repos/deploy-controller/node_modules/degenerator/src/index.ts:6:1)
at __require (/Users/asquithea/repos/deploy-controller/.sst/artifacts/aff14e6d/src/handlers/command.js:26:44)
at node_modules/pac-resolver/dist/index.js (/Users/asquithea/repos/deploy-controller/node_modules/pac-resolver/src/index.ts:3:1)
The artifacts
directory contains only the compiled lambda (command.ts
-> command.js
).
contextify.js
is part of the vm2
library, which tries to load it dynamically, like this:
contextifyScript: loadAndCompileScript(`${__dirname}/contextify.js`, '(function(require, host) { ', '\n})'),
So this looks like a bundling problem: I guess the vm2
library assumes a standard node_modules
structure.
I see there are some control options for bundling in the construct, but at this point I don’t really know what I’m doing.
Is this similar enough to someone else’s problem that you can offer any advice? TIA.Koen A
01/05/2022, 12:41 PMConnectionNotFoundError2: Connection "default" was not found.
at ConnectionNotFoundError2.TypeORMError2 [as constructor] (/test-project/.sst/artifacts/8a2bd957/src/consumer.js:74327:28)
The ormconfig.json file is located in my project root as it should but it seems the transpiled JS file in the artifacts folder cannot find it.
Are project root json files not included or is some manual build step needed?Christian Kaindl
01/05/2022, 2:10 PMFranco Gotusso
01/05/2022, 2:12 PMMike McCall
01/05/2022, 2:46 PMsst test
, it does it's sst
thing before running the test and this step seems to be the main issue. However, when we use jest directly (like in a standard cdk project) mocking works fine and test pass the same. Are we missing anything by using the testing library directly?Daniel Gato
01/05/2022, 4:03 PMAWS SAM template
The second set of required data is in the Metadata section that helps AWS SAM manage the container images. When a container is created, a new tag is added to help identify that image. By default, Docker uses the tag, latest. However, AWS SAM passes an explicit tag name to help differentiate between functions. That tag name is a combination of the Lambda function resource name, and the DockerTag value found in the Metadata. Additionally, the DockerContext points to the folder containing the function code and Dockerfile identifies the name of the Dockerfile used in building the container image.
In addition to changes in the template.yaml file, AWS SAM also uses the Docker CLI to build container images. Each Lambda function has a Dockerfile that instructs Docker how to construct the container image for that function. The Dockerfile for the HelloWorldFunction is at hello-world/Dockerfile.
Source: https://aws.amazon.com/blogs/compute/using-container-image-support-for-aws-lambda-with-aws-sam/
Ayo
01/05/2022, 6:48 PMDan Van Brunt
01/05/2022, 9:25 PMnode_modules
even though I have a .eslintignore
?
…and my tsconfig.json
has this…
"exclude": ["./jest.config.js", "./node_modules/**/*", "./build/**/*", "./frontend/**/*", "./contentful-frontend/**/*"],
"include": ["lib", "src"]
Dan Van Brunt
01/05/2022, 9:55 PMErik Robertson
01/05/2022, 10:59 PMPreparing your SST app
Synthesizing CDK
TypeError: Cannot read property 'map' of undefined
at HttpUserPoolAuthorizer2.bind (/Users/erik/src/dataworks/dwam-back/node_modules/@aws-cdk/aws-apigatewayv2-authorizers/lib/http/user-pool.ts:40:49)
at new HttpRoute (/Users/erik/src/dataworks/dwam-back/node_modules/@aws-cdk/aws-apigatewayv2/lib/http/route.ts:116:64)
at Api.addRoute (/Users/erik/src/dataworks/dwam-back/node_modules/@serverless-stack/resources/src/Api.ts:461:19)
at /Users/erik/src/dataworks/dwam-back/node_modules/@serverless-stack/resources/src/Api.ts:302:12
at Array.forEach (<anonymous>)
at Api.addRoutes (/Users/erik/src/dataworks/dwam-back/node_modules/@serverless-stack/resources/src/Api.ts:301:25)
at new Api (/Users/erik/src/dataworks/dwam-back/node_modules/@serverless-stack/resources/src/Api.ts:271:10)
at new MyStack (/Users/erik/src/dataworks/dwam-back/stacks/MyStack.js:60:17)
at Object.main (/Users/erik/src/dataworks/dwam-back/stacks/index.js:5:3)
at Object.<anonymous> (/Users/erik/src/dataworks/dwam-back/.build/run.js:94:16)
Jeff Cordova
01/06/2022, 9:51 AMcurl -X POST \
-H 'Content-Type: application/json' \
-d '{"content":"Hello World","attachment":"hello.jpg"}' \
<https://ps699rk4di.execute-api.ap-southeast-1.amazonaws.com>
the response I get is
{"message":"Not Found"}%
I checked the cloudwatch for logs but there are no logs yet so I think it's not calling the API yet. Any idea what's happening here? Or how do I check what's happening in the background? Thank you!gio
01/06/2022, 10:27 AMexport default class MyStack extends Stack {
constructor(scope, id, props) {
super(scope, id, props);
const topic = new Topic(this, "Topic");
this.addOutputs({
TopicArn: { value: topic.snsTopic.topicArn, exportName: "MyTopicArn" },
});
}
}
David Garcia
01/06/2022, 2:15 PMstack failed to deploy
Update of resource type is not permitted. The new template modifies resource type of the following resources [...apigateway name]
I didn't explicitly set any protections on the apigateway. Does anyone know how to disable this behavior? It seems to have only popped up after standing up an api gatewayRoss Gerbasi
01/06/2022, 4:03 PMnpm i
my project. I understand they are probably not major for what I am doing, and probably more involved in the creation of my stacks then my actual running code. But any plans to clear these up? an audit wants me to roll back to cli version 4.5
Secondly I am noticing the typescript watcher does not recompile when I update dependent files only when I update the handler.ts
file itself. So changes to any imports it has doesn't trigger a recompile. Again just more of an annoyance but would like to know if there is a solution.
Lastly I am getting a warning about using TS 4.5.4 every time I make a change. This is coming from the @typescript-eslint/typescript-estree
package. I have included a screenshot of that as well. Looks like we have version 4.33.0 in our node_modules but the latest is 5.9.0. I guess maybe dependencies in general need a boost? I would hope pushing up TS related packages wouldn't cause to much of an issue.
For completeness I am using @serverless-stack/cli
and @serverless-stack/resources
0.56.2. Thanks in advance!