public async Task <CloudFormationResponse> FunctionHandler(CloudFormationEvent <StartCodeBuild> @event, ILambdaContext context) { var json = JsonConvert.SerializeObject(@event, Formatting.Indented); context.Logger.LogLine(json); object data; try { switch (@event.RequestType) { case RequestType.Create: data = await Create(@event, context); break; case RequestType.Update: data = await Update(@event, context); break; case RequestType.Delete: data = await Delete(@event, context); break; } return(await CloudFormationResponse.CompleteCloudFormationResponse(new { SomeData = "some data" }, @event, context)); } catch (Exception ex) { return(await CloudFormationResponse.CompleteCloudFormationResponse(new { Error = ex.ToString() }, @event, context)); } }
public CloudFormationResponse LoadMasterData(LoadMasterDataCustomCloudformationEvent request, ILambdaContext context) { try { string UniqueIdGenerated = SecurityHelper.GetSha256Hash($"{request.StackId}:{request.LogicalResourceId}"); DynamoDBMasterItem1 item1 = new DynamoDBMasterItem1( UniqueIdGenerated, Convert.ToString(Guid.NewGuid()), "Rohit Srivastava", "Senior Consultant", "29", "Advisory"); context.Logger.LogLine($"Input event invoked: {JsonConvert.SerializeObject(request)}"); DynamoDBHelper dynamoDBHelper = new DynamoDBHelper(context, this.isLocalDebug); context.Logger.LogLine($"Custom cloudformation event request type: {request.RequestType}"); //Since this is not basically creation of any custom resource , rather initial data load , we donot need //to care about anything other than the CREATE request type if (string.Equals(request.RequestType, Constants.CloudFormationCreateRequestType)) { dynamoDBHelper.putItemTable1(item1, request.ResourceProperties.TableName); //Success - data inserted properly in the dynamoDB CloudFormationResponse objResponse = new CloudFormationResponse( Constants.CloudformationSuccessCode, "Custom Resource Creation Successful", $"{request.StackId}-{request.LogicalResourceId}-DataLoad", request.StackId, request.RequestId, request.LogicalResourceId, item1 ); return(objResponse.CompleteCloudFormationResponse(request, context).GetAwaiter().GetResult()); } else { CloudFormationResponse objResponse = new CloudFormationResponse( Constants.CloudformationSuccessCode, "Do nothing.Data will be pushed in only when stack event is Create", context.LogStreamName, request.StackId, request.RequestId, request.LogicalResourceId, null ); return(objResponse.CompleteCloudFormationResponse(request, context).GetAwaiter().GetResult()); } } catch (Exception ex) { context.Logger.LogLine($"StartupProgram::LoadMasterData => {ex.Message}"); context.Logger.LogLine($"StartupProgram::LoadMasterData => {ex.StackTrace}"); //Error - log it into the cloudformation console CloudFormationResponse objResponse = new CloudFormationResponse( Constants.CloudformationErrorCode, ex.Message, context.LogStreamName, request.StackId, request.RequestId, request.LogicalResourceId, null ); return(objResponse.CompleteCloudFormationResponse(request, context).GetAwaiter().GetResult()); } }