AWS IAM Instance Profile

This page shows how to write Terraform and CloudFormation for IAM Instance Profile and write them securely.

aws_iam_instance_profile (Terraform)

The Instance Profile in IAM can be configured in Terraform with the resource name aws_iam_instance_profile. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

iam-instances.tf#L1
resource "aws_iam_instance_profile" "Dublin_ecs_instance_profile_wifi" {
  name = "Dublin-ecs-instance-profile-wifi"
  path = "/"
  role = "Dublin-ecs-instance-role-wifi"
}

iamip.tf#L1
resource "aws_iam_instance_profile" "aws-elasticbeanstalk-ec2-role" {
    name = "aws-elasticbeanstalk-ec2-role"
    path = "/"
    role = "aws-elasticbeanstalk-ec2-role"
}

iam.tf#L1
resource "aws_iam_instance_profile" "s3_service" {
  name = "s3-service-user"
  role = aws_iam_role.s3_service.name
}

resource "aws_iam_role" "s3_service" {

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides an IAM instance profile.

Tips: Best Practices for The Other AWS IAM Resources

In addition to the aws_iam_account_password_policy, AWS IAM has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_iam_account_password_policy

Ensure AWS IAM account password policies requires long passwords

It's better to enforce the use of long and complex passwords to reduce the risk of bruteforce attacks.

Review your AWS IAM settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::IAM::InstanceProfile (CloudFormation)

The InstanceProfile in IAM can be configured in CloudFormation with the resource name AWS::IAM::InstanceProfile. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

Ec2_Securian.yml#L61
    Type: AWS::IAM::InstanceProfile
    Properties:
      Path: "/"
      InstanceProfileName: SFGGodwillprofiletest
      Roles:
        - !Ref GodwillEC2Role
security-stack.yml#L4
    Type: 'AWS::IAM::InstanceProfile'
    Properties:
      Path: /
      Roles:
        - !Ref AutomationServiceRole

CodeDeploy_IAM_Role_User_Policies.yml#L30
    Type: "AWS::IAM::InstanceProfile"
    Properties:
      Path: "/"
      Roles:
        -
          Ref: "CodeDeployServiceRole"
roles-for-ec2.yml#L28
    Type: "AWS::IAM::InstanceProfile"
    Properties:
      Path: "/"
      InstanceProfileName: EcsNode
      Roles:
        - !Ref EcsNode
iam-baseline.yml#L16
        Type: AWS::IAM::InstanceProfile
        DependsOn: rSysAdminRole
        Properties:
            Path: /
            Roles:
              - !Ref rSysAdminRole
role.cf.json#L99
            "Type": "AWS::IAM::InstanceProfile",
            "Properties": {
                "InstanceProfileName": "pan",
                "Path": "peter/",
                "Roles": [
                    {
resourceIamProfile.json#L5
            "Type" : "AWS::IAM::InstanceProfile",
            "Properties" : {
                "Path" : "/",
                "Roles" : [
                    {
                        "Ref" : "Role1"
resources.json#L5
            "Type" : "AWS::IAM::InstanceProfile",
            "Properties" : {
                "Path" : "/",
                "Roles" : [
                    {
                        "Ref" : "InstanceRole"
identity-iam-roles.cloudformation.json#L284
         "Type":"AWS::IAM::InstanceProfile",
         "Properties":{
            "Path":"/identity/",
            "Roles":[
               {
                  "Ref":"IdentityBuilderProdRole"
csye6225-cf-ci-cd.json#L17
      "Type" : "AWS::IAM::InstanceProfile",
      "Properties" : {
        "Path" : "/",
        "Roles" : [
          {
            "Ref" : "EC2ToS3BucketRole"

Parameters

Explanation in CloudFormation Registry

Creates a new instance profile. For information about instance profiles, see Using instance profiles. For information about the number of instance profiles you can create, see IAM object quotas in the IAM User Guide.

Frequently asked questions

What is AWS IAM Instance Profile?

AWS IAM Instance Profile is a resource for IAM of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS IAM Instance Profile?

For Terraform, the alphagov/govwifi-terraform, tappoflw/tappo1 and jeremychauvet/aws-elasticbeanstalk-showroom source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the godwillngwanah/AWS-Sol-Arch-02, dpaquette77/aws-voip and duonghanu/github-codedeploy source code examples are useful. See the CloudFormation Example section for further details.