concept tag in category aws

appears as: tags, Tag, tag, tags, A tag, tag
AWS CloudFormation in Action

This is an excerpt from Manning's book AWS CloudFormation in Action.

It provides a management layer that enables you to create, update, and delete resources in your Azure subscription. You use management features, like access control, locks, and tags, to secure and organize your resources after deployment.

2.5.4   Let’s Give Our Instance a Name and a Tag

Now, for fun, we want to add a name and a tag to our EC2 instance.  We’ll talk about updating stacks in chapter 3, and more about tags in chapter 6. Meanwhile, let’s just delete the stack, by going to the AWS console, choosing CloudFormation and then clicking the radio button next to “myteststack”

Listing 2.11 Creating an EC2 instance and assigning tags
{
    "Resources": {
    "MyServer": {
        "Type": "AWS::EC2::Instance",
        "Properties": {
            "InstanceType": "t2.micro",    #A
            "ImageId": "ami-02ccb28830b645a41",    #B
            "Tags" : [
                {"Key" : "Name",
                  "Value" : "MyServer"},
                {  "Key" : "Stage",
                    "Value" : "Dev"},    C
                     ]
                     }
                }
                 }
            
}
Amazon Web Services in Action, Second Edition

This is an excerpt from Manning's book Amazon Web Services in Action, Second Edition.

The next step is to specify tags for your infrastructure, as illustrated by figure 2.5. A tag consists of a key and a value, and can be used to add metadata to all parts of your infrastructure. You can use tags to differentiate between testing and production resources, add a cost center to easily track costs in your organization, or mark resources that belong to a certain application if you host multiple applications in the same AWS account.

Figure 2.5. Creating the stack for the proof-of-concept: step 3 of 4

Figure 2.5 shows how to configure the tag. In this example, you’ll use a tag to mark all resources that belong to the wordpress system. This will help you to easily find all the parts of your infrastructure later. Use a custom tag consisting of the key system and the value wordpress. Afterward, press the Next button to proceed to the next step. You can define your own tags as long as the key name is shorter than 128 characters and the value has fewer than 256 characters.

In our first example, you will create a Lambda function that performs periodic health checks for your website. This will teach you how to use the Management Console and offer a blueprint for getting started with AWS Lambda quickly. In our second example, you will learn how to write your own Python code and deploy a Lambda function in an automated way using CloudFormation. Your Lambda function will automatically add a tag to newly launched EC2 instances. At the end of the chapter, we’ll show you additional use cases like building web applications, Internet of Things (IoT) back ends, or processing data with AWS Lambda.

Time to write some Python code! The following listing for lambda_function.py shows the function, which receives an event from CloudTrail indicating that an EC2 has been launched recently, and adds a tag including the name of the instance’s owner. The AWS SDK for Python 3.6, named boto3, is provided out-of-the-box in the Lambda runtime environment for Python 3.6. In this example you are using the AWS SDK to create a tag for the EC2 instance ec2.create_tags(...). See the Boto 3 Documentation at https://boto3.readthedocs.io/en/latest/index.html if you are interested in the details of boto3.

Listing 7.4. Lambda function adding a tag to EC2 instance
import boto3
ec2 = boto3.client('ec2')                                              #1

def lambda_handler(event, context):                                    #2

  userName = event['detail']['userIdentity']['arn'].split('/')[1]      #3
  instanceId = event['detail']['responseElements']
 ['instancesSet']['items'][0]['instanceId']                          #4
  print("Adding owner tag " + userName + " to instance " + instanceId + ".")
  ec2.create_tags(Resources=[instanceId,],
 Tags=[{'Key': 'Owner', 'Value': userName},])                        #5
  return

Adding a tag that states who owns an instance solves all these use cases. A tag can be added to an EC2 instance or almost any other AWS resource, and consists of a key and a value. Tags can be used to add information to a resource, filter resources, attribute costs to resources, as well as to restrict access. See “Tagging Your Amazon EC2 Resources” at http://mng.bz/pEJN for more details.

It is possible to add tags specifying the owner of an EC2 instance manually. But sooner or later, someone will forget to add the owner tag. There is a better solution for that! You will implement and deploy a Lambda function that adds a tag containing the name of the user who launched an EC2 instance automatically in the following section. But how do you execute a Lambda function every time an EC2 instance is launched, so that you can add the tag?

Learn Amazon Web Services in a Month of Lunches

This is an excerpt from Manning's book Learn Amazon Web Services in a Month of Lunches.

The Tag Instance page that comes up next gives you the opportunity to assign an identifying name to your instance. As you’ll learn later in the book, tags can be useful for quickly finding specific objects from among long lists of resources. For now, though, feel free to type any useful identifying name (like, say, MyInstance)—or nothing at all—in this field.

As you probably already figured out on your own, tags are key/value pairs that can be associated with individual pieces of AWS infrastructure. A key/value pair, by the way, is a couple of text strings used to help identify an object’s purpose and context. A key called name might, when associated with a new EC2 instance you’re launching, be given the value MyNewEC2Instance—to set it apart from your old EC2 instance, whose value for name might have been something like MyFirstEC2Instance. This label is used only for identification purposes and has no impact on the way the instance will operate. Unlike other key/value pair systems, AWS keys don’t need to be unique.

I haven’t used tags up to this point because I’ve assumed that your AWS account is fairly new and probably running only one or two examples of any particular object (one EC2 instance, one VPC, one EBS volume, and so on). When your list has only one item, there isn’t much point in differentiating it from ... well, from what, exactly? But my long-term goal is to turn you into a hard-core, seasoned Amazonian with all kinds of projects running on all kinds of resources. Once you’ve reached the “all kinds” plateau, things may get complicated if left unmanaged. So now’s the time to start thinking carefully about some structural and design considerations that, over time, can make a difference.

The purpose of the Tag Editor is to make it easy for you to find resources by tag and then, if desired, create and apply new tags to all or some of the results. But I’m going to use the Tag Editor to illustrate how you can also use tags to filter for specific resources. Figure 10.5 shows how I entered the AWS region I wanted to search, along with specific resource types (I went with All Resource Types in this case), and the key domain. I then entered the transactions-primary value for the key and clicked Find Resources. The instance, security group, and S3 bucket were returned, but nothing else—which was exactly what I wanted.

Figure 10.5. The Tag Editor page, where you can create and manage tags and also search for specific tag ranges

Don’t just sit there staring. Go add a tag to a resource in your own account—perhaps one of your security groups. Then go through at least the initial steps of launching an EC2 instance, and see how much easier it is to select a security group that’s been tagged from among a long list.