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
resource "aws_iam_instance_profile" "Dublin_ecs_instance_profile_wifi" {
name = "Dublin-ecs-instance-profile-wifi"
path = "/"
role = "Dublin-ecs-instance-role-wifi"
}
resource "aws_iam_instance_profile" "aws-elasticbeanstalk-ec2-role" {
name = "aws-elasticbeanstalk-ec2-role"
path = "/"
role = "aws-elasticbeanstalk-ec2-role"
}
resource "aws_iam_instance_profile" "s3_service" {
name = "s3-service-user"
role = aws_iam_role.s3_service.name
}
resource "aws_iam_role" "s3_service" {
Parameters
-
arn
optional computed - string -
create_date
optional computed - string -
id
optional computed - string -
name
optional computed - string -
name_prefix
optional - string -
path
optional - string -
role
optional - string -
tags
optional - map from string to string -
unique_id
optional computed - string
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.
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.
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
Type: AWS::IAM::InstanceProfile
Properties:
Path: "/"
InstanceProfileName: SFGGodwillprofiletest
Roles:
- !Ref GodwillEC2Role
Type: 'AWS::IAM::InstanceProfile'
Properties:
Path: /
Roles:
- !Ref AutomationServiceRole
Type: "AWS::IAM::InstanceProfile"
Properties:
Path: "/"
Roles:
-
Ref: "CodeDeployServiceRole"
Type: "AWS::IAM::InstanceProfile"
Properties:
Path: "/"
InstanceProfileName: EcsNode
Roles:
- !Ref EcsNode
Type: AWS::IAM::InstanceProfile
DependsOn: rSysAdminRole
Properties:
Path: /
Roles:
- !Ref rSysAdminRole
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"InstanceProfileName": "pan",
"Path": "peter/",
"Roles": [
{
"Type" : "AWS::IAM::InstanceProfile",
"Properties" : {
"Path" : "/",
"Roles" : [
{
"Ref" : "InstanceRole"
"Type" : "AWS::IAM::InstanceProfile",
"Properties" : {
"Path" : "/",
"Roles" : [
{
"Ref" : "Role1"
"Type":"AWS::IAM::InstanceProfile",
"Properties":{
"Path":"/identity/",
"Roles":[
{
"Ref":"IdentityBuilderProdRole"
"Type" : "AWS::IAM::InstanceProfile",
"Properties" : {
"Path" : "/",
"Roles" : [
{
"Ref" : "EC2ToS3BucketRole"
Parameters
-
InstanceProfileName
optional - String -
Path
optional - String -
Roles
required - List
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.