Exemplo n.º 1
0
        public async Task <CloudFormationResponse> FunctionHandler(SnapStackRequest input, ILambdaContext context)
        {
            if (string.Equals("Delete", input.RequestType, StringComparison.OrdinalIgnoreCase))
            {
                return(await CloudFormationResponse.CompleteCloudFormationResponse(null, input, context));
            }

            return(await SnapshotStackResources(input, context));
        }
Exemplo n.º 2
0
        private async Task <CloudFormationResponse> SnapshotStackResources(SnapStackRequest input, ILambdaContext context)
        {
            try
            {
                var stackName = input.StackId.Split('/')[1];
                var results   = await GetStackResource(input, stackName);
                await StoreResultsInDynamo(results, input.ResourceProperties, stackName);

                return(await CloudFormationResponse.CompleteCloudFormationResponse(null, input, context));
            }
            catch (Exception ex)
            {
                return(await CloudFormationResponse.CompleteCloudFormationResponse(ex, input, context));
            }
        }
Exemplo n.º 3
0
        private async Task <string> GetStackResource(SnapStackRequest input, string stackName)
        {
            var cfClient = new AmazonCloudFormationClient(RegionEndpoint.EUWest1);


            //TODO: Paginate
            var request = new ListStackResourcesRequest
            {
                StackName = stackName
            };
            var json         = new JObject();
            var resourceList = await cfClient.ListStackResourcesAsync(request);

            foreach (var resource in resourceList.StackResourceSummaries)
            {
                json.Add($"{resource.ResourceType}_{resource.LogicalResourceId}", resource.PhysicalResourceId);
            }

            return(json.ToString(Formatting.Indented));
        }