We are currently trying to deploy an amp application via import { Builder } from '@sls-next/lambda-at-edge'.
the application is compiling and locale builds with prod, int or dev are showing an execellent working amp app (where all script tags are loaded.
if we build the app with AWS CDK using the { Builder } from '@sls-next/lambda-at-edge' and deploy the app, the markup is correct while the amp scripts are not injested and missing. They are not part of the build.
If we have, for example, an simple page with an the normal next build adds the javascript file automatically.
So we just add into our page and next build adds a to our page.
It looks like the AmpOptimizer is not executed.
Actual behavior
AMP javascripts scripts are missing
Expected behavior
AMP javascripts scripts are injected during build process automatically
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { AppConfiguration } from '../lib/common/AppConfiguration';
import { Builder } from '@sls-next/lambda-at-edge';
import { CdkLambdaatedge } from '../lib/cdk-lambdaatedge';
const builder = new Builder('.', './build', {
cmd: './node_modules/.bin/next',
cwd: process.cwd(),
args: ['build'],
minifyHandlers: true,
// it is recommended to let your CF distribution do the compression as per the docs - https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html
// however there have been issues in the past where CF doesn't compress lambda@edge responses, so we provide our own implementation in case is needed
enableHTTPCompression: false
});
builder
.build()
.then(() => {
const app = new cdk.App();
const configUsEast1: AppConfiguration = {
env: {
account: app.node.tryGetContext(stage).account,
region: 'us-east-1'
},
};
new CdkLambdaatedge(app, `amp-lambdaatedge`, {
...configUsEast1,
});
})
.catch((e) => {
console.log(e);
process.exit(1);
});
../lib/cdk-lambdaatedge
import { Duration, Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { AppConfiguration } from './common/AppConfiguration';
import { NextJSLambdaEdge } from '@sls-next/cdk-construct';
import { Runtime } from 'aws-cdk-lib/aws-lambda';
export class CdkLambdaatedge extends Stack {
constructor(scope: Construct, id: string, props: AppConfiguration) {
super(scope, id, props);
const nextApp = new NextJSLambdaEdge(this, `AmpApp`, {
serverlessBuildOutDir: './build',
timeout: Duration.seconds(30),
memory: {
imageLambda: 1024,
defaultLambda: 1024,
apiLambda: 1024
},
runtime: Runtime.NODEJS_14_X,
withLogging: true,
description: `${id} : Functions Lambda@Edge for the application`
});
}
}
Issue Summary
We are currently trying to deploy an amp application via import { Builder } from '@sls-next/lambda-at-edge'. the application is compiling and locale builds with prod, int or dev are showing an execellent working amp app (where all script tags are loaded.
if we build the app with AWS CDK using the { Builder } from '@sls-next/lambda-at-edge' and deploy the app, the markup is correct while the amp scripts are not injested and missing. They are not part of the build.
If we have, for example, an simple page with an the normal next build adds the javascript file automatically.
So we just add into our page and next build adds a to our page.
It looks like the AmpOptimizer is not executed.
Actual behavior
AMP javascripts scripts are missing
Expected behavior
AMP javascripts scripts are injected during build process automatically
Steps to reproduce
build a simple amp page like
Screenshots/Code/Configuration/Logs
CDK contructs:
./bin/cdk-app.ts
../lib/cdk-lambdaatedge
Versions
Additional context
Apps are compiling and running locale.
We could add a post processor script in our pipeline like manual triggering the AmpOptimizer if possible.