Calculating AWS snapshot usage cost programatically

Multi tool use
Multi tool use





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am planning to calculate snapshot usage cost using a script.



As per the documentation if we have GB-month value we can calculate the cost based on this. Is there any way to calculate snapshot size and its age? I could not find any method to fetch the snapshot size. When I describe a snapshot I do get volume-size in snapshotInfo but I don't think that's the snapshot size. Also the age of a snapshot is not defined in the description. Only the timestamp when the snapshot was initiated is in the output.



I don't want the cost for all the snapshots. I will be filtering snapshots based on a custom tag. I saw https://aws.amazon.com/blogs/aws/new-cost-allocation-for-ebs-snapshots/ but this is via the UI and needs special permissions.










share|improve this question





























    0















    I am planning to calculate snapshot usage cost using a script.



    As per the documentation if we have GB-month value we can calculate the cost based on this. Is there any way to calculate snapshot size and its age? I could not find any method to fetch the snapshot size. When I describe a snapshot I do get volume-size in snapshotInfo but I don't think that's the snapshot size. Also the age of a snapshot is not defined in the description. Only the timestamp when the snapshot was initiated is in the output.



    I don't want the cost for all the snapshots. I will be filtering snapshots based on a custom tag. I saw https://aws.amazon.com/blogs/aws/new-cost-allocation-for-ebs-snapshots/ but this is via the UI and needs special permissions.










    share|improve this question

























      0












      0








      0








      I am planning to calculate snapshot usage cost using a script.



      As per the documentation if we have GB-month value we can calculate the cost based on this. Is there any way to calculate snapshot size and its age? I could not find any method to fetch the snapshot size. When I describe a snapshot I do get volume-size in snapshotInfo but I don't think that's the snapshot size. Also the age of a snapshot is not defined in the description. Only the timestamp when the snapshot was initiated is in the output.



      I don't want the cost for all the snapshots. I will be filtering snapshots based on a custom tag. I saw https://aws.amazon.com/blogs/aws/new-cost-allocation-for-ebs-snapshots/ but this is via the UI and needs special permissions.










      share|improve this question














      I am planning to calculate snapshot usage cost using a script.



      As per the documentation if we have GB-month value we can calculate the cost based on this. Is there any way to calculate snapshot size and its age? I could not find any method to fetch the snapshot size. When I describe a snapshot I do get volume-size in snapshotInfo but I don't think that's the snapshot size. Also the age of a snapshot is not defined in the description. Only the timestamp when the snapshot was initiated is in the output.



      I don't want the cost for all the snapshots. I will be filtering snapshots based on a custom tag. I saw https://aws.amazon.com/blogs/aws/new-cost-allocation-for-ebs-snapshots/ but this is via the UI and needs special permissions.







      amazon-web-services amazon-s3 amazon-ec2 aws-sdk






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 3 at 21:50









      aajaaj

      1,50262258




      1,50262258
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The cost and usage report is the only way to capture this information. It is not accessible through the service API.



          EBS snapshots are -- logically -- the same size as the source volume, because every EBS snapshot contains a reference to a stored representation of every single block on the volume.



          But it's only a reference -- a pointer -- because EBS doesn't store the actual data blocks inside the snapshot itself. It maintains a mapping and has the ability to determine which blocks are unchanged from snapshot to snapshot, so that it doesn't redundantly store them.



          The price you pay for a given snapshot is directly determined by how many blocks in that snapshot are different from those in the most recent, prior snapshot of the same volume that still exists. Deleting older snapshots preserves any blocks that are still needed for restoring newer snapshots, and thus rolls the cost of those blocks forward into snapshots that still exist, with the cost shifting into the oldest snapshot that still needs the blocks after any older ones are deleted.



          So the cost of a given snapshot changes as previous snapshots of the same volume are deleted.



          Also:




          Only the timestamp when the snapshot was initiated is in the output.




          That's the age. Snapshots are snapshots -- an image of the disk at the moment in time the snapshot was initiated. Regardless of how long the snapshot takes to run, the data it captures is the data as it existed on the volume when the snapshot was initiated.






          share|improve this answer
























          • So if I multiply size of volume and total time snapshot has been active that will give me GB-month required to calculate the billing cost?

            – aaj
            Jan 4 at 2:11











          • That is only true if the snapshot is the only snapshot in existence for the volume, and if each block on the volume has had data written to it, ever. Otherwise you will always come up with a cost that is much higher than reality. The cost and usage reports are the only place to actually find this information. You can configure these reports to be automatically and continually be exported to an S3 bucket for later processing.

            – Michael - sqlbot
            Jan 4 at 3:53













          • And there is no API way to get the number of blocks in use in S3 at any particular point of time? If there is a S3 bucket which only contains only the snapshots can I not find the total blocks in use there to calculate the cost?

            – aaj
            Jan 7 at 17:13













          • Correct, there is not. The bucket that EBS stores snapshot fragments in is owned by the EBS service -- it's not a bucket accessible to you. You'll also notice on billing that EBS (EC2) charges you for the storage, not S3.

            – Michael - sqlbot
            Jan 7 at 17:58












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030292%2fcalculating-aws-snapshot-usage-cost-programatically%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The cost and usage report is the only way to capture this information. It is not accessible through the service API.



          EBS snapshots are -- logically -- the same size as the source volume, because every EBS snapshot contains a reference to a stored representation of every single block on the volume.



          But it's only a reference -- a pointer -- because EBS doesn't store the actual data blocks inside the snapshot itself. It maintains a mapping and has the ability to determine which blocks are unchanged from snapshot to snapshot, so that it doesn't redundantly store them.



          The price you pay for a given snapshot is directly determined by how many blocks in that snapshot are different from those in the most recent, prior snapshot of the same volume that still exists. Deleting older snapshots preserves any blocks that are still needed for restoring newer snapshots, and thus rolls the cost of those blocks forward into snapshots that still exist, with the cost shifting into the oldest snapshot that still needs the blocks after any older ones are deleted.



          So the cost of a given snapshot changes as previous snapshots of the same volume are deleted.



          Also:




          Only the timestamp when the snapshot was initiated is in the output.




          That's the age. Snapshots are snapshots -- an image of the disk at the moment in time the snapshot was initiated. Regardless of how long the snapshot takes to run, the data it captures is the data as it existed on the volume when the snapshot was initiated.






          share|improve this answer
























          • So if I multiply size of volume and total time snapshot has been active that will give me GB-month required to calculate the billing cost?

            – aaj
            Jan 4 at 2:11











          • That is only true if the snapshot is the only snapshot in existence for the volume, and if each block on the volume has had data written to it, ever. Otherwise you will always come up with a cost that is much higher than reality. The cost and usage reports are the only place to actually find this information. You can configure these reports to be automatically and continually be exported to an S3 bucket for later processing.

            – Michael - sqlbot
            Jan 4 at 3:53













          • And there is no API way to get the number of blocks in use in S3 at any particular point of time? If there is a S3 bucket which only contains only the snapshots can I not find the total blocks in use there to calculate the cost?

            – aaj
            Jan 7 at 17:13













          • Correct, there is not. The bucket that EBS stores snapshot fragments in is owned by the EBS service -- it's not a bucket accessible to you. You'll also notice on billing that EBS (EC2) charges you for the storage, not S3.

            – Michael - sqlbot
            Jan 7 at 17:58
















          1














          The cost and usage report is the only way to capture this information. It is not accessible through the service API.



          EBS snapshots are -- logically -- the same size as the source volume, because every EBS snapshot contains a reference to a stored representation of every single block on the volume.



          But it's only a reference -- a pointer -- because EBS doesn't store the actual data blocks inside the snapshot itself. It maintains a mapping and has the ability to determine which blocks are unchanged from snapshot to snapshot, so that it doesn't redundantly store them.



          The price you pay for a given snapshot is directly determined by how many blocks in that snapshot are different from those in the most recent, prior snapshot of the same volume that still exists. Deleting older snapshots preserves any blocks that are still needed for restoring newer snapshots, and thus rolls the cost of those blocks forward into snapshots that still exist, with the cost shifting into the oldest snapshot that still needs the blocks after any older ones are deleted.



          So the cost of a given snapshot changes as previous snapshots of the same volume are deleted.



          Also:




          Only the timestamp when the snapshot was initiated is in the output.




          That's the age. Snapshots are snapshots -- an image of the disk at the moment in time the snapshot was initiated. Regardless of how long the snapshot takes to run, the data it captures is the data as it existed on the volume when the snapshot was initiated.






          share|improve this answer
























          • So if I multiply size of volume and total time snapshot has been active that will give me GB-month required to calculate the billing cost?

            – aaj
            Jan 4 at 2:11











          • That is only true if the snapshot is the only snapshot in existence for the volume, and if each block on the volume has had data written to it, ever. Otherwise you will always come up with a cost that is much higher than reality. The cost and usage reports are the only place to actually find this information. You can configure these reports to be automatically and continually be exported to an S3 bucket for later processing.

            – Michael - sqlbot
            Jan 4 at 3:53













          • And there is no API way to get the number of blocks in use in S3 at any particular point of time? If there is a S3 bucket which only contains only the snapshots can I not find the total blocks in use there to calculate the cost?

            – aaj
            Jan 7 at 17:13













          • Correct, there is not. The bucket that EBS stores snapshot fragments in is owned by the EBS service -- it's not a bucket accessible to you. You'll also notice on billing that EBS (EC2) charges you for the storage, not S3.

            – Michael - sqlbot
            Jan 7 at 17:58














          1












          1








          1







          The cost and usage report is the only way to capture this information. It is not accessible through the service API.



          EBS snapshots are -- logically -- the same size as the source volume, because every EBS snapshot contains a reference to a stored representation of every single block on the volume.



          But it's only a reference -- a pointer -- because EBS doesn't store the actual data blocks inside the snapshot itself. It maintains a mapping and has the ability to determine which blocks are unchanged from snapshot to snapshot, so that it doesn't redundantly store them.



          The price you pay for a given snapshot is directly determined by how many blocks in that snapshot are different from those in the most recent, prior snapshot of the same volume that still exists. Deleting older snapshots preserves any blocks that are still needed for restoring newer snapshots, and thus rolls the cost of those blocks forward into snapshots that still exist, with the cost shifting into the oldest snapshot that still needs the blocks after any older ones are deleted.



          So the cost of a given snapshot changes as previous snapshots of the same volume are deleted.



          Also:




          Only the timestamp when the snapshot was initiated is in the output.




          That's the age. Snapshots are snapshots -- an image of the disk at the moment in time the snapshot was initiated. Regardless of how long the snapshot takes to run, the data it captures is the data as it existed on the volume when the snapshot was initiated.






          share|improve this answer













          The cost and usage report is the only way to capture this information. It is not accessible through the service API.



          EBS snapshots are -- logically -- the same size as the source volume, because every EBS snapshot contains a reference to a stored representation of every single block on the volume.



          But it's only a reference -- a pointer -- because EBS doesn't store the actual data blocks inside the snapshot itself. It maintains a mapping and has the ability to determine which blocks are unchanged from snapshot to snapshot, so that it doesn't redundantly store them.



          The price you pay for a given snapshot is directly determined by how many blocks in that snapshot are different from those in the most recent, prior snapshot of the same volume that still exists. Deleting older snapshots preserves any blocks that are still needed for restoring newer snapshots, and thus rolls the cost of those blocks forward into snapshots that still exist, with the cost shifting into the oldest snapshot that still needs the blocks after any older ones are deleted.



          So the cost of a given snapshot changes as previous snapshots of the same volume are deleted.



          Also:




          Only the timestamp when the snapshot was initiated is in the output.




          That's the age. Snapshots are snapshots -- an image of the disk at the moment in time the snapshot was initiated. Regardless of how long the snapshot takes to run, the data it captures is the data as it existed on the volume when the snapshot was initiated.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 4 at 1:33









          Michael - sqlbotMichael - sqlbot

          95.7k13141207




          95.7k13141207













          • So if I multiply size of volume and total time snapshot has been active that will give me GB-month required to calculate the billing cost?

            – aaj
            Jan 4 at 2:11











          • That is only true if the snapshot is the only snapshot in existence for the volume, and if each block on the volume has had data written to it, ever. Otherwise you will always come up with a cost that is much higher than reality. The cost and usage reports are the only place to actually find this information. You can configure these reports to be automatically and continually be exported to an S3 bucket for later processing.

            – Michael - sqlbot
            Jan 4 at 3:53













          • And there is no API way to get the number of blocks in use in S3 at any particular point of time? If there is a S3 bucket which only contains only the snapshots can I not find the total blocks in use there to calculate the cost?

            – aaj
            Jan 7 at 17:13













          • Correct, there is not. The bucket that EBS stores snapshot fragments in is owned by the EBS service -- it's not a bucket accessible to you. You'll also notice on billing that EBS (EC2) charges you for the storage, not S3.

            – Michael - sqlbot
            Jan 7 at 17:58



















          • So if I multiply size of volume and total time snapshot has been active that will give me GB-month required to calculate the billing cost?

            – aaj
            Jan 4 at 2:11











          • That is only true if the snapshot is the only snapshot in existence for the volume, and if each block on the volume has had data written to it, ever. Otherwise you will always come up with a cost that is much higher than reality. The cost and usage reports are the only place to actually find this information. You can configure these reports to be automatically and continually be exported to an S3 bucket for later processing.

            – Michael - sqlbot
            Jan 4 at 3:53













          • And there is no API way to get the number of blocks in use in S3 at any particular point of time? If there is a S3 bucket which only contains only the snapshots can I not find the total blocks in use there to calculate the cost?

            – aaj
            Jan 7 at 17:13













          • Correct, there is not. The bucket that EBS stores snapshot fragments in is owned by the EBS service -- it's not a bucket accessible to you. You'll also notice on billing that EBS (EC2) charges you for the storage, not S3.

            – Michael - sqlbot
            Jan 7 at 17:58

















          So if I multiply size of volume and total time snapshot has been active that will give me GB-month required to calculate the billing cost?

          – aaj
          Jan 4 at 2:11





          So if I multiply size of volume and total time snapshot has been active that will give me GB-month required to calculate the billing cost?

          – aaj
          Jan 4 at 2:11













          That is only true if the snapshot is the only snapshot in existence for the volume, and if each block on the volume has had data written to it, ever. Otherwise you will always come up with a cost that is much higher than reality. The cost and usage reports are the only place to actually find this information. You can configure these reports to be automatically and continually be exported to an S3 bucket for later processing.

          – Michael - sqlbot
          Jan 4 at 3:53







          That is only true if the snapshot is the only snapshot in existence for the volume, and if each block on the volume has had data written to it, ever. Otherwise you will always come up with a cost that is much higher than reality. The cost and usage reports are the only place to actually find this information. You can configure these reports to be automatically and continually be exported to an S3 bucket for later processing.

          – Michael - sqlbot
          Jan 4 at 3:53















          And there is no API way to get the number of blocks in use in S3 at any particular point of time? If there is a S3 bucket which only contains only the snapshots can I not find the total blocks in use there to calculate the cost?

          – aaj
          Jan 7 at 17:13







          And there is no API way to get the number of blocks in use in S3 at any particular point of time? If there is a S3 bucket which only contains only the snapshots can I not find the total blocks in use there to calculate the cost?

          – aaj
          Jan 7 at 17:13















          Correct, there is not. The bucket that EBS stores snapshot fragments in is owned by the EBS service -- it's not a bucket accessible to you. You'll also notice on billing that EBS (EC2) charges you for the storage, not S3.

          – Michael - sqlbot
          Jan 7 at 17:58





          Correct, there is not. The bucket that EBS stores snapshot fragments in is owned by the EBS service -- it's not a bucket accessible to you. You'll also notice on billing that EBS (EC2) charges you for the storage, not S3.

          – Michael - sqlbot
          Jan 7 at 17:58




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030292%2fcalculating-aws-snapshot-usage-cost-programatically%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          u0mCoAdoRXksXJ9M0r0iPLAXiLlY,R C
          Vw36i,78zWpJ8l 6u8 bR sOE0uCmDvkR eBzCy D U6sVo9d,o0lMoxr1ph,BLC3BM p sVjX1No5H 0tvI,AdAecapx

          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas