Skip to content

Instantly share code, notes, and snippets.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Cognito Resources for your Service.
Resources:
LambdaForCloudFormation:
Type: 'AWS::IAM::Role'
Properties:
RoleName: LambdaForCloudFormation
AssumeRolePolicyDocument:
import { Callback, Context } from 'aws-lambda';
import AWS from 'aws-sdk';
import sendResponse from './CloudFormationSendResponse';
export default async (
event: any,
context: Context,
callback: Callback<any>) => {
try {
const cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider();
import { Callback, Context } from 'aws-lambda';
import AWS from 'aws-sdk';
import sendResponse from './CloudFormationSendResponse';
export default async (
event: any,
context: Context,
callback: Callback<any>) => {
try {
switch (event.RequestType) {
import axios from 'axios';
interface SendRequest {
ResponseStatus: string;
StackId: string;
RequestId: string;
LogicalResourceId: string;
ResponseData: any;
ResponseURL: string;
}
private final AmazonDynamoDB mClient = AmazonDynamoDBClientBuilder
.standard()
.build();
private final DynamoDB dynamoDB = new DynamoDB(mClient);
private Context mContext;
public Response handleRequest(final Request request, final Context context) {
mContext = context;
...
private void logSomething() {
mContext.getLogger().log("something");
}
private ExampleComponent mComponent;
public SimpleLoggingHandler() {
mComponent = DaggerExampleComponent.builder().build();
}
public class Injector {
public static ExampleComponent getInjector(final Context context) {
return DaggerExampleComponent
.builder()
.dynamoDBModule(new DynamoDBModule())
.lambdaModule(new LambdaModule(context))
.build();
}
}
public class SimpleLoggingHandler implements RequestHandler<String, Boolean> {
@Inject LambdaLogger mLogger;
public Boolean handleRequest(final String request, final Context context) {
Injector.getInjector(context).inject(this);
mLogger.log(String.format("Received Request: %s", request));
return true;
}
@Singleton
@Component(modules = {
LambdaModule.class
})
public interface ExampleComponent {
void inject(SimpleLoggingHandler simpleLoggingHandler);
}