Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec2: look up AWS managed Prefix Lists #15115

Open
1 of 2 tasks
alanraison opened this issue Jun 14, 2021 · 32 comments
Open
1 of 2 tasks

ec2: look up AWS managed Prefix Lists #15115

alanraison opened this issue Jun 14, 2021 · 32 comments
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@alanraison
Copy link
Contributor

alanraison commented Jun 14, 2021

There is currently no way to lookup the IP of an AWS-managed Prefix List (i.e. those for S3 and DynamoDB).

Use Case

In order to use an S3 or DynamoDB Gateway endpoint, with a Security Group which allows only specific outbound access, it is necessary to lookup the com.amazonaws.<region>.s3 or com.amazonaws.<region>.dynamodb Prefix List's ID. This is currently not possible.

Proposed Solution

Add the ability to look up a Prefix List by prefix list ID. I don't know if this requires changes in Cloudformation.

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@alanraison alanraison added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 14, 2021
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Jun 14, 2021
@alanraison alanraison changed the title (ec2): look up AWS managed Prefix Lists ec2: look up AWS managed Prefix Lists Jun 14, 2021
@njlynch njlynch added effort/medium Medium work item – several days of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jun 22, 2021
@njlynch njlynch removed their assignment Jun 22, 2021
@njlynch
Copy link
Contributor

njlynch commented Jun 22, 2021

There is no current CloudFormation support for this. The guidance I have seen elsewhere is to use a Custom Resource to do the lookup. See the description of #13668 for one example of doing that lookup via a Custom Resource.

This is something we could conceivably integrate into the CDK, but it's not clear yet how broad an impact it would have or where it would live. I am unassigning and marking this issue as p2, which means that we are unable to work on this immediately.

We use +1s to help prioritize our work, and are happy to revaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization. In the meantime, I hope the linked workaround helps!

@ramiro
Copy link

ramiro commented Oct 21, 2021

See also #9568.

@markoperich
Copy link

+1

2 similar comments
@havenith
Copy link

havenith commented Dec 3, 2021

+1

@gottschalkj-fmr
Copy link

+1

@github-actions github-actions bot added p1 and removed p2 labels Jul 7, 2022
@github-actions
Copy link

github-actions bot commented Jul 7, 2022

This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.

@comcalvi comcalvi assigned comcalvi and unassigned comcalvi Jul 12, 2022
@falkvonohlen
Copy link

+1

4 similar comments
@igormukhin
Copy link

+1

@tisauro
Copy link

tisauro commented Sep 7, 2022

+1

@elginlam-amazon
Copy link

+1

@markrekveld
Copy link

+1

@MrArnoldPalmer MrArnoldPalmer added p2 and removed p1 labels Jan 27, 2023
@dennisschaaf
Copy link

+1

@mvs5465
Copy link

mvs5465 commented Mar 9, 2023

Does anyone know if you can reference prefix lists using CfnResourceShare?

@acatala-sistrol
Copy link

+1

1 similar comment
@antoniordz96
Copy link

+1

@mrgum
Copy link

mrgum commented Apr 13, 2023

+1

1 similar comment
@VitalyUsik
Copy link

+1

@corymhall
Copy link
Contributor

This looks like something we might want to add a fromLookup method that uses synth time lookups.

@cjkent
Copy link

cjkent commented Jun 13, 2023

+1

1 similar comment
@deepak3082
Copy link

+1

@WinterYukky
Copy link
Contributor

If this value is an immutable value for each region, I think it's also conceivable to set it to Region info :)
https://docs.aws.amazon.com/cdk/api/v2/docs/region-info-readme.html

@sotoiwa
Copy link

sotoiwa commented Jun 28, 2023

Related: #24921

@mrgrain
Copy link
Contributor

mrgrain commented Jul 14, 2023

Region fact is fine, but I think we should start adding these kind of slowly (never) changing automated look-ups things into
https://github.com/cdklabs/awscdk-service-spec so it can be re-used here.

@bericp1
Copy link

bericp1 commented Jul 27, 2023

+1

@cogwirrel
Copy link
Member

As a workaround until this is implemented properly, I used AwsCustomResource to achieve the same result. Sharing it here in case it's useful :)

import { IPrefixList, PrefixList } from 'aws-cdk-lib/aws-ec2';
import { Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam';
import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from 'aws-cdk-lib/custom-resources';
import { Construct } from 'constructs';

export interface AwsManagedPrefixListProps {
  /**
   * Name of the aws managed prefix list.
   * See: https://docs.aws.amazon.com/vpc/latest/userguide/working-with-aws-managed-prefix-lists.html#available-aws-managed-prefix-lists
   * eg. com.amazonaws.global.cloudfront.origin-facing
   */
  readonly name: string;
}

export class AwsManagedPrefixList extends Construct {
  public readonly prefixList: IPrefixList;

  constructor(scope: Construct, id: string, { name }: AwsManagedPrefixListProps) {
    super(scope, id);

    const prefixListId = new AwsCustomResource(this, 'GetPrefixListId', {
      onUpdate: {
        service: '@aws-sdk/client-ec2',
        action: 'DescribeManagedPrefixListsCommand',
        parameters: {
          Filters: [
            {
              Name: 'prefix-list-name',
              Values: [name],
            },
          ],
        },
        physicalResourceId: PhysicalResourceId.of(`${id}-${this.node.addr.slice(0, 16)}`),
      },
      policy: AwsCustomResourcePolicy.fromStatements([
        new PolicyStatement({
          effect: Effect.ALLOW,
          actions: ['ec2:DescribeManagedPrefixLists'],
          resources: ['*'],
        }),
      ]),
    }).getResponseField('PrefixLists.0.PrefixListId');

    this.prefixList = PrefixList.fromPrefixListId(this, 'PrefixList', prefixListId);
  }
}

With example usage:

const cfOriginFacingPrefixList = new AwsManagedPrefixList(this, 'CloudfrontOriginPrefixList', {
  name: 'com.amazonaws.global.cloudfront.origin-facing',
}).prefixList;

@danib-ntt-sky
Copy link

+1

@werebear73-tritelph
Copy link

+1 - the workaround doesn't work on .NET (see above mention)

@ggzik-copperleaf
Copy link

+1, We ran into the same issue (also using cdk in dotnet) and used the Custom Resource solution as well:

private string GetPrefixListId(string stackId, IEnvironment env, string prefixListName)
{
    var customResourceName = $"{stackId}-GetPrefixListId";
    return new AwsCustomResource(this, "GetPrefixListId", new AwsCustomResourceProps {
        FunctionName = customResourceName,
        LogRetention = RetentionDays.ONE_DAY,
        OnUpdate = new AwsSdkCall {
            Service = "@aws-sdk/client-ec2",
            Action = "DescribeManagedPrefixListsCommand",
            Parameters = new Dictionary<string, object> {
                {
                    "Filters", new Dictionary<string, object>[] {
                        new Dictionary<string, object> {
                            { "Name", "prefix-list-name" },
                            { "Values", new string[] { prefixListName } }
                        }
                    }
                },
            },
            PhysicalResourceId = PhysicalResourceId.Of($"{stackId}-{Node.Addr.Substring(0, 16)}"),
        },
        Policy = AwsCustomResourcePolicy.FromStatements(new[] {
            new PolicyStatement(new PolicyStatementProps {
                Effect = Effect.ALLOW,
                Actions = new[] { "ec2:DescribeManagedPrefixLists" },
                Resources = new[] { "*" }, // ec2:DescribeManagedPrefixLists must be executed against resource *
                Conditions = new Dictionary<string, object> {{
                    "StringEquals", new Dictionary<string, string> {
                        { "aws:PrincipalAccount", env.Account },
                        { "aws:RequestedRegion", env.Region }
                    }
                }}
            }),
        }),
    }).GetResponseField("PrefixLists.0.PrefixListId");
}

Note that the policy has to use Resource: * because that is the only resource ec2:DescribeManagedPrefixLists, so to make it a bit more secure we added conditions to scope the action down to within our account.

@zvonimir-bednarcik
Copy link

+1

1 similar comment
@isunli
Copy link

isunli commented Feb 26, 2024

+1

@alexbaileymembr
Copy link

We are going to implement the workaround above but have a slightly different use case of needing to lookup prefix lists by name. It's only ID available at the moment which varies between accounts, regions etc. It would be good to know if a FromLookup or FromName option at Synth time is the way to go. If it is, then I'd feel more comfortable taking a stab at this.

@carlo-vassallo
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests