Open jeandek opened 3 years ago
If anyone has created a template please share.
Hi, I am working on it. I guess, I could share my application (with cdk) on this Sunday as reference of how to integrate it. π
@ShivamJoker please refer my post to get overview and link to full demo app using this library. βΊοΈ
If it's okay, I would love to contribute to share my demo app as an example of how-to section. π
This is my implementation:
import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm";
import { CloudFrontRequestHandler } from "aws-lambda";
import { Authenticator } from "cognito-at-edge";
β
// Retrieve the parameter configuration and create an Authenticator instance.
// The authenticator instance will be cached between invocations.
const ssm = new SSMClient({ region: process.env.CONFIG_PARAMETER_REGION });
const authenticatorPromise = ssm
.send(new GetParameterCommand({ Name: process.env.CONFIG_PARAMETER_NAME }))
.then(config => new Authenticator({ ...JSON.parse(config.Parameter!.Value!), logLevel: 'trace' }));
β
export const handler: CloudFrontRequestHandler = async event => {
try {
const authenticator = await authenticatorPromise;
const response = await authenticator.handle(event);
return response;
} catch (error) {
console.error(error);
return { body: '401 Unauthorised', status: '401' };
}
};
Please note that this requires to manually prepare a stringified version of the configuration under a known key in the AWS Systems Manager Parameter Store. This is certainly not the only way to do that.
Please note that @aws-sdk/client-ssm
and all @aws-sdk
packages are only available by default in the Node.js 18+ AWS Lambda runtime.
What would you like to be added:
Sample CDK and CloudFormation templates to show how to integrate the AWS services together with the package.
Why is this needed:
The desired architecture may be intimidating to users who have not done it before.