EC2 Image Builder in AWS Organization

0

Hi,

My EC2 Image Builder is in AWS Organization, it's not the root account. I want to create images and automatically share them with all accounts and newly created accounts? Is it possible to do that?

Thanks

3개 답변
0
수락된 답변

Actually, I just found out that there is a built-in functionality of image pipeline to share with the whole Org/OUnit. So, I don't need any Lambdas. Thank you for your replies.

profile picture
답변함 8달 전
  • True, thats possible, only if you want to put the latest image to SSM in the specific accounts to help people to use that parameter while automation creation of instances you would need to have a lambda function

  • This is the correct way to do it.

0

Yes, sharing Amazon Machine Images (AMIs) across accounts in an AWS Organization is possible. Here's a more direct approach to your question:

  1. When EC2 Image Builder completes a build, it produces an AMI. You can modify the permissions of this AMI to be shared with other AWS accounts.

  2. Sharing with Specific Accounts:

  • Go to the EC2 console.
  • Under "Images", select "AMIs".
  • Select your AMI, click on "Actions", and then choose "Modify Image Permissions".
  • Under "Add account", you can specify the AWS account numbers with which you want to share the AMI.
  1. To automatically share the AMI with all accounts in your organization, you would need to set up an automation (e.g., using AWS Lambda) that:
  • Detects the creation of a new AMI using CloudWatch Events.
  • Shares the AMI with all accounts in the AWS Organization by modifying the AMI permissions.

I hope this helps! If this solution works for you, please accept the answer. Otherwise, do leave a comment, and I'll try to assist you.

profile picture
답변함 8달 전
profile pictureAWS
전문가
검토됨 8달 전
  • This is redundant. Use the built in function in Image Builder to share the AMIs with the Org/OU.

0

Here is an example Lambda to share an AMI to an AWS Organization:

import boto3
import logging
logger = logging.getLogger()

ec2client = boto3.client('ec2')
orgclient = boto3.client('organizations')

try: 
    accounts = orgclient.list_accounts()
    accountlist = []
    for account in accounts['Accounts']:
        if account['Status'] == 'ACTIVE':
            accountlist.append(account['Id'])
except():
    logger.error("Could not get Account ids")
try:
    print(accountlist)
    logger.info("Share new AMI with Organization Accounts")
    response = ec2client.modify_image_attribute(
    Attribute='launchPermission',
    ImageId="YOURIMAGEID",
    OperationType='add',
    UserIds=accountlist
    )
except(ec2client.Client.exceptions):
    logger.error("Could not share AMI: YOURIMAGEID.")
profile picture
David
답변함 8달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠