Kevin Clark
01/15/2021, 11:30 PMfunctions:
listShowNoteSets:
handler: functions/listShowNoteSets.main
events:
- http:
path: shownotes/{PK}
method: get
cors: true
A function definition like that, without authorizer: aws_iam
in it should still be generally accessible by an unauthorized request?
I’m getting a Missing Authentication Token
message back. I can see in API Gateway where there is no authorization required for the path.
The lambda function itself only reads data and works when I’m logged in with a Cognito user.
Do you have any pointers where this could be blocked? Cognito seems like a spot but I haven’t gotten into that and it my next target.
Thanks for any advice!Luis De La Hoz
01/18/2021, 7:23 PMserverless-bundle
from v.2.0.0 to v4.2.0? I am having problems deploying, due to a memory overflow, caused by two things: ForkTsCheckerWebpackPlugin
and package: individually: true
, and I read that in the newest version is solved, but I keep getting errors.Seth Geoghegan
01/19/2021, 5:50 PMPaulo
01/23/2021, 8:08 AMsst.json
Does it make sense or there's a more elegant way?
btw, should I ask this type of question here or in the #sst channel? 🙂Luis De La Hoz
01/23/2021, 5:42 PMPaulo
01/24/2021, 6:29 PMgetSecretValue()
being the cause as far as I understand.
It's very weird because:
• All the functions are in the same serverless.yml
and share the same VPC configuration (which is already set up to allow internet access) and the other functions with the same type of calls (SecretsManager, RDS, and external addresses) work perfectly;
• It doesn't seem to be an external access problem because the HTTP calls to the Internet work fine, only the secrets manager get stuck;
• I noticed that if I change the internet address I'm calling for another (e.g. google.com) it works without timing out the getSecretValue()
call.
• Since the external address, in this case, is another lambda, I tested calling it directly by using the AWS SDK instead of making an HTTP request (via axios), but in this case, the timeout happens again :S
Any clues? Has anyone already passed for a similar problem?Pål Brattberg
01/25/2021, 3:40 PMsst start
. When I'm done developing, I deploy again to make sure I replace the mocked functions.
Is this correctly understood?
Thank you for your time!Pål Brattberg
01/26/2021, 5:02 AM.eslintignore
file with just a single *
in, but lines like these spam my screen on `sst start`:
/Users/pal/dev/peasy/node_modules/@aws-cdk/cx-api/lib/cloud-assembly.js
0:0 warning File ignored by default. Use "--ignore-pattern '!node_modules/*'" to override
That a file is (correctly) ignored seems like TMI. Any ideas on how to supress this?Pål Brattberg
01/29/2021, 12:13 AM*Unzipped size must be smaller than 250956732 bytes*
for a small function now. Looking in .build
it does not look good. Will investigate, but if anybody here recognizes the problem, please let me know 🙂Ross Coundon
01/30/2021, 12:25 PMOMWGetThumbPhoto: {
handler: '.build/main/handler/someHandler.handleGetThumb',
layers: [
sharpLayerArn
],
events: [
{
http: {
method: 'get',
path: 'resourceConfig/{resourceId}/thumb',
cors: true
}
}
]
},
In the code lambda function the image is retrieved like this:
public static async getFileByName(bucket: string, name: string): Promise<AWS.S3.GetObjectOutput> {
const s3 = S3Factory.getS3();
const getObjectParams: GetObjectRequest = {
Bucket: bucket,
Key: name,
};
return s3.getObject(getObjectParams).promise();
}
The data for the response is built like this (none of the exceptions throw and image is determined to be of type image/png):
public static async getPhotoByName(name: string, fullsize = true): Promise<PhotoAndMime> {
const photoName = fullsize ? name : `${this.SMALL_PHOTO_PREFIX}${name}`;
const photo = await FileStorage.getFileByName(this.getBucketId(), photoName);
if (!photo || !photo.Body) throw new Error(`Failed to retrieve image file for photo '${photoName}'`);
let photoStr = '';
const base64Photo = photo.Body.toString('base64');
const type = await FileType.fromBuffer(photo.Body as Buffer);
if (!type) throw new Error(`Invalid or missing image type for for photo '${photoName}'`);
<http://log.info|log.info>(`File Type determined to be: ${type.mime}`);
photoStr = `data:${type.mime};base64,${base64Photo}`;
return { photo: photoStr, mimeType: type.mime };
}
Then the response is returned like this
async function handleGetCommon(event: APIGatewayProxyEvent, fullSize: boolean): Promise<APIGatewayProxyResult> {
let response: APIGatewayProxyResult;
try {
const result = await ResourcePhotoService.getPhotoById(resourceId, datasetId, fullSize);
if (result) {
response = {
statusCode: 200,
headers: { 'Content-Type': result.mimeType },
body: result.photo,
isBase64Encoded: true,
};
} else {
response = { statusCode: 204, body: '' };
}
} catch (err) {
response = HandlerUtils.handleCaughtError(err, `Could not retrieve resource config photo`);
}
Utils.addCorsHeaders(response);
return response;
}
The web application that calls the API Gateway uses axios like this:
const { data } = await axios.get(url, {
headers: {
accept: 'image/jpg, image/png',
Authorization: `Bearer ${token}`,
},
responseType: 'arraybuffer',
params,
});
and tries to process the response the data uses this function to convert the response to an image data URL
export function convertBinaryToImage(rawPhoto) {
return new Promise((resolve) => {
if (rawPhoto?.byteLength > 0) {
FileType.fromBuffer(rawPhoto).then((type) => {
const blob = new Blob([rawPhoto], { type: type.mime });
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = () => {
return resolve(reader.result); // data url
};
});
}
});
}
However it cannot determine the file type, something seems to be getting corrupted along the way. Has anyone solved the problem of retrieving a private image from an S3 bucket and return that via API Gateway to be displayed on a web page? I feel like I’m missing some serverless configuration somewhere. I’ve tried setting response.contentHandling CONVERT_TO_TEXT and CONVERT_TO_BINARY but that didn’t seem to make any difference.Paulo
01/30/2021, 2:59 PMhttpApi
event type in sls), which I also didn't know.
So, using httpApi
I'm able to define the required scopes
for my function. Is there a way to do something similar using the regular http
event type and a custom authorizer?
Also, what do you usually use in terms of AGW API type: REST or HTTP? I saw this page but would like to know about real experiences...
ThanksPål Brattberg
02/05/2021, 3:21 PM===============
Deploying app
===============
Preparing your SST app
Transpiling source
Linting source
Deploying stacks
Error: Argument to Intrinsic must be a plain value object, got () => {
throw new Error('Duration.toString() was used, but .toSeconds, .toMinutes or .toDays should have been called instead');
}
at new Intrinsic (/Users/pal/dev/peasy/node_modules/@aws-cdk/core/lib/private/intrinsic.ts:39:13)
at Function.asAny (/Users/pal/dev/peasy/node_modules/@aws-cdk/core/lib/token.ts:102:48)
at Function.asString (/Users/pal/dev/peasy/node_modules/@aws-cdk/core/lib/token.ts:79:53)
at Duration.toString (/Users/pal/dev/peasy/node_modules/@aws-cdk/core/lib/duration.ts:219:18)
at new Duration (/Users/pal/dev/peasy/node_modules/@aws-cdk/core/lib/duration.ts:95:46)
at Function.seconds (/Users/pal/dev/peasy/node_modules/@aws-cdk/core/lib/duration.ts:29:12)
at new Function (/Users/pal/dev/peasy/node_modules/@serverless-stack/resources/src/Function.ts:127:31)
at createFunction (/Users/pal/dev/peasy/lib/cdk-common.js:96:10)
at new AnalysisStack (/Users/pal/dev/peasy/services/analysis/sst-stack.js:27:38)
at Object.main (/Users/pal/dev/peasy/lib/index.js:11:3)
There was an error synthesizing your app.
error Command failed with exit code 1.
Downgrading to 0.7.3
fixes thisAndreas
02/10/2021, 11:20 PMPaulo
02/12/2021, 8:27 AMBma
02/13/2021, 2:37 PMCamilo Rios
02/13/2021, 2:48 PMCloud assembly schema version mismatch: Maximum schema version supported is 7.0.0, but found 9.0.0
When building locally I noticed that the manifest.json
version created has version 9.0.0, not sure if its related and how to fix it. Does anyone run into a similar issue? Thanks!Camilo Rios
02/13/2021, 8:24 PMsst start
on a monorepo with the sample ts api example but getting an error. The debugger starts just fine, but as soon as I make an api request it fails.MAURICIO VALDIVIA MONZON
02/15/2021, 2:45 PMAndy Averbuch
02/16/2021, 11:28 PMPaulo
02/17/2021, 12:02 PMhandler: bin/admin.funcName
?camilo segura
02/17/2021, 2:41 PMMike Dubinsky
02/18/2021, 4:38 PM- !ImportValue ${self:custom.sstApp}-TableArn
Julien Goux
02/19/2021, 7:57 PMJulien Goux
02/19/2021, 7:57 PMSione
02/19/2021, 9:18 PM/lib
to another name /stacks
. Or is it strictly lib. Not a big deal, just wondering, I just tried deploying with another name and it's expecting /lib
.MAURICIO VALDIVIA MONZON
02/20/2021, 1:39 PMJohn Nguyen
02/20/2021, 8:42 PMJulien Goux
02/22/2021, 10:43 AMMAURICIO VALDIVIA MONZON
02/22/2021, 10:38 PMAndreas
02/22/2021, 11:49 PM