-
Notifications
You must be signed in to change notification settings - Fork 249
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
Pass parameters to templates in aws-api-gateway-* #891
Comments
While we recommend allowing the CDK/CloudFormation to create machine generated names for resources, as that allows multiple stacks to be created within 1 account/1 region, we see two ways to accomplish what you seek:
|
The latter is what I meant by I have not tried the create method yet to see if the variable substitution there works. If it does I'll submit a PR to make the same changes to read. |
Does this PR provide what you need? It's merged and should be released this week. |
I don't think it does, but I will try once it's released. I'm not 100% sure if this is a bug or operator error. If the latter once I figure it out I can update documentation. This example is in the test file in V2.31.0
I can get the
|
Hi - Can you please provide a little more information. When I deploy this test, I can see the |
Sorry for the delay, but I had not worked with typescript before. I was able to deploy, but could not confirm the additional request was working, as I could not tell it apart from the default template. My Goal is to be able to use a sort key and not use 'id' as the primary key. This works in Typescript export class ApiGatewayTsStack extends Stack {
} This does not work in Python: `from aws_solutions_constructs.aws_apigateway_dynamodb import ApiGatewayToDynamoDB, ApiGatewayToDynamoDBProps class ApiGatewayBugStack(Stack):
The cloud formation template.json seems to be OK:
But when it's executed in API Gateway test page, the name is not resolved: Response: Logs Snippet: I have not tested any other languages. |
I'd like for it to work with table props vs existing table, but that is just a nice to have. This method will work if we can get the Table Name in python. Could very easily be operator error. |
hi @Gamecock - Thank you for the additional info. Looking at your example above, I'm guessing things in the After thinking for a moment on the new/existing table point, I think currently this would only be possible using an existing table, as we can't reference a solutions-constructs created table from outside the construct until its created, and at that point, it would be too late as we need to pass these properties in during creation time. from aws_cdk import (
Stack
)
import aws_cdk.aws_dynamodb as dynamodb
from constructs import Construct
from aws_solutions_constructs.aws_apigateway_dynamodb import ApiGatewayToDynamoDB
import json
class PythonStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
partition_key_name = 'id'
existing_table_obj = dynamodb.Table(self, 'existing-table',
partition_key = dynamodb.Attribute(
name= partition_key_name,
type= dynamodb.AttributeType.STRING,
),
point_in_time_recovery= True,
encryption= dynamodb.TableEncryption.AWS_MANAGED,
billing_mode= dynamodb.BillingMode.PAY_PER_REQUEST
)
read_request_template = json.dumps({
"TableName": existing_table_obj.table_name,
"KeyConditionExpression": f"{partition_key_name} = :v1",
"ExpressionAttributeValues": {
":v1": {
"S": f"input.params('{partition_key_name}')"
},
}
})
ApiGatewayToDynamoDB(self, 'ApiGatewayToDynamoDB',
read_request_template=read_request_template,
existing_table_obj=existing_table_obj
) |
Thanks, I was able to validate this works for me. Do you want a documentation update to say the request templates require the use of an existing template, or should it actually throw an error if you provide a template without an existingTableObject? |
Based on aws-api_gateway-dynamodb
The constructor has read_request_template etc.
The only way I can make it work in the python SDK is hard code the table name.
I can see the default template index.ts line 268.
I cannot figure out how to pass parameters into the template.
the create request template looks like it explicitly replaces {$Table}
The text was updated successfully, but these errors were encountered: