-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
custom_resources: parameters are not passed for a custom resource calling ELBv2:DescribeListeners #27126
Comments
I attempted to reproduce this in TypeScript, however the call succeeded. Here is my code: const ssmparam = new ssm.StringParameter(this, 'Parameter', { stringValue: 'myloadbalancerarn' });
const ssmcr = new cr.AwsCustomResource(this, 'SSMCustomResource', {
onUpdate: {
service: 'SSM',
action: 'getParameter',
parameters: {
Name: ssmparam.parameterName
},
physicalResourceId: cr.PhysicalResourceId.of(Date.now().toString()),
},
policy: cr.AwsCustomResourcePolicy.fromStatements([
new iam.PolicyStatement({
actions: ['*'],
resources: ['*'],
effect: iam.Effect.ALLOW,
})
]),
});
const elbcr = new cr.AwsCustomResource(this, 'ELBCustomResource', {
onUpdate: {
service: 'ELBv2',
action: 'describeListeners',
parameters: {
LoadBalancerArn: ssmcr.getResponseField('Parameter.Value').toString()
},
physicalResourceId: cr.PhysicalResourceId.of(Date.now().toString()),
},
policy: cr.AwsCustomResourcePolicy.fromStatements([
new iam.PolicyStatement({
actions: ['*'],
resources: ['*'],
effect: iam.Effect.ALLOW,
})
]),
}); You mention
Could you share the synthesized CloudFormation template? You should see something like the following for your LoadBalancerArn "ELBCustomResource5A118D7C": {
"Type": "Custom::AWS",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"AWS679f53fac002430cb0da5b7982bd22872D164C4C",
"Arn"
]
},
"Create": {
"Fn::Join": [
"",
[
"{\"service\":\"ELBv2\",\"action\":\"describeListeners\",\"parameters\":{\"LoadBalancerArn\":\"",
{
"Fn::GetAtt": [
"SSMCustomResourceFF6A08D8",
"Parameter.Value"
]
},
"\"},\"physicalResourceId\":{\"id\":\"1694729238854\"}}"
]
]
}, |
Hi Peter, Here is what I get in the generated templates (BugReportStack.template.json) |
I've found the key difference between what you're doing and what I'm doing and it's in the policy statement for the DescribeListeners call. Yours is:
while mine is:
Once I matched my policy to yours, it worked. The question I have then is: What should the policy have been to allow the parameter to be passed? |
This leads into another issue with my not being able to retrieve the raw response and iterate over it. getResponseField doesn't help unless you know exactly what those response fields are. I see this is discussed here: #22826 Is there any work on a solution to read the raw response from the Lambda function? |
I'm not exactly sure off the top of my head, I'd have to look into that.
There isn't a way to do that unfortunately. The "Fn::GetAtt": [
"SSMCustomResourceFF6A08D8",
"Parameter.Value"
] If you need to loop over an arbitrary list, that requires creating "Fn::GetAtt": [
"ELBCustomResourceFF6A08D8",
"Listeners.n.LoadBalancerArn"
] But, we won't know what My response here addresses what the workaround is. If you'd like more info or a detailed explanation on why this is the recommended solution, please see the "Commit |
I think it might need to be:
|
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Describe the bug
I am unable to retrieve a list of all listeners associated with an Application Load Balancer by ARN using a CDK custom resource. During deployment, CDK generates an error that the assumed role is not authorized to perform the action.
I am able to successfully retrieve the list of listeners using the CLI:
aws elbv2 describe-listeners --load-balancer-arn="arn:aws:elasticloadbalancing:us-east-1:_account_:loadbalancer/app/sandbox-alb/<alb>"
I am using a two-step process which involves a custom resource to pull the current value of an SSM parameter containing the ARN of the load balancer and passing the result as a parameter to DescribeListeners.
Expected Behavior
The AwsCustomResource should successfully retrieve the listeners given the specified load balancer arn. The returned value should be equivalent to the output of the aws elbv2 describe-listeners command shown above.
Current Behavior
The deployment fails:
When I check CloudTrail, the "DescribeListeners" event shows requestParameters as null instead of the load balancer ARN.
custom_resource_event_record.txt
successful_aws_cmd_event_record.txt
Reproduction Steps
Prerequisite:
Store an SSM parameter "alb_arn" : "arn:aws:elasticloadbalancing:us-east-1:account_id:loadbalancer/app/sandbox-alb/"
Create a stack stack1 and retrieve the value of "alb_arn" using a custom resource, attempt to retrieve the listeners using a separate custom resource:
Sample project reproducing the issue
bug-report.zip
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.95.1 (build ae455d8)
Framework Version
No response
Node.js Version
v18.14.2
OS
macOS Ventura version 13.5.2
Language
Java
Language Version
Java (17)
Other information
No response
The text was updated successfully, but these errors were encountered: