'Why my cloudformation template is over 1 MB?

I created a SAM project and created a simple hello world lambda. After executing:

sam package --template-file template.yaml --output-template-file output.yaml --s3-bucket bucket-child-s3

It sucessfully uploaded to S3, the problem comes when I execute:

    let params = {
        StackName: 'stack-child',
        Capabilities: ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"],
        TemplateURL: 'https://s3.amazonaws.com/bucket-child-s3/9f63c6d47e7b8dde84306e20197e557b'
    };
    const result = await cloudformation.createStack(params).promise();

I get this error:

Template may not exceed 1000000 bytes in size

I looked at my s3 bucket and the file size is 28.7 MB, I dont know why is this big when I am uploading only a lambda with responds with a hello world message.

What do I need to do to minimize the file size?


I read that a possible solution was to add the property of the lambdas:

CodeUri: src/

But it only uploads the code of the lambda itself and I get this error:

Template contains invalid characters



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source