Skip to content

Commit

Permalink
Release 1.64.0 (to main) #3093
Browse files Browse the repository at this point in the history
Release 1.64.0 (to main)
  • Loading branch information
aahung authored Apr 6, 2023
2 parents 1e29fc8 + c9244ae commit c916e66
Show file tree
Hide file tree
Showing 55 changed files with 7,161 additions and 282 deletions.
1 change: 1 addition & 0 deletions .cfnlintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ ignore_templates:
- tests/translator/output/**/globals_for_function.json # RuntimeManagementConfig
- tests/translator/output/**/function_with_runtime_config.json # RuntimeManagementConfig
- tests/translator/output/**/managed_policies_minimal.json # Intentionally has non-existent managed policy name
- tests/translator/output/**/function_with_mq.json # Property "EventSourceArn" can Fn::GetAtt to a resource of types [AWS::DynamoDB::GlobalTable, AWS::DynamoDB::Table, AWS::Kinesis::Stream, AWS::Kinesis::StreamConsumer, AWS::SQS::Queue]
ignore_checks:
- E2531 # Deprecated runtime; not relevant for transform tests
- W2531 # EOL runtime; not relevant for transform tests
Expand Down
1 change: 1 addition & 0 deletions DEVELOPMENT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ Integration tests are covered in detail in the [INTEGRATION_TESTS.md file](INTEG
For new properties of SAM resources, use [`Property`](https://github.com/aws/serverless-application-model/blob/c5830b63857f52e540fec13b29f029458edc539a/samtranslator/model/__init__.py#L36-L45) or [`PassThroughProperty`](https://github.com/aws/serverless-application-model/blob/dd79f535500158baa8e367f081d6a12113497e45/samtranslator/model/__init__.py#L48-L56) instead of [`PropertyType`](https://github.com/aws/serverless-application-model/blob/c39c2807bbf327255de8abed8b8150b18c60f053/samtranslator/model/__init__.py#L13-L33). This avoids [sneaky bugs](https://github.com/aws/serverless-application-model/pull/2495#discussion_r976715242) and ensures valid templates do not cause transform failures.

For new properties of CloudFormation resources, use [`GeneratedProperty`](https://github.com/aws/serverless-application-model/blob/79452f69bc1fcf918b8625c2f9005c74ab874801/samtranslator/model/__init__.py#L74-L82). It performs no runtime validation, reducing the risk of valid values causing transform failures.
7. **Write all new code under [`samtranslator/internal`](https://github.com/aws/serverless-application-model/tree/develop/samtranslator/internal) if possible.** This ensures we don't increase our "public" library interface and cause unnecessary breakages to consumers. While Python doesn't have private access modifiers, we assume anything [by convention private](https://peps.python.org/pep-0008/#descriptive-naming-styles) or under `internal` to be internal code, not bound by typical expectations of backward compatibility.

Code conventions
----------------
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ test-fast:
pytest -x --cov samtranslator --cov-report term-missing --cov-fail-under 95 -n auto tests/

test-cov-report:
pytest --cov samtranslator --cov-report term-missing --cov-report html --cov-fail-under 95 tests/
pytest --cov samtranslator --cov-report term-missing --cov-report html --cov-fail-under 95 -n auto tests/
open htmlcov/index.html &> /dev/null || true

integ-test:
pytest --no-cov integration/
Expand Down
1 change: 1 addition & 0 deletions integration/combination/test_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def tearDown(self):

@parameterized.expand(
[
("combination/connector_appsync_to_lambda",),
("combination/connector_appsync_to_table",),
("combination/connector_function_to_function",),
("combination/connector_restapi_to_function",),
Expand Down
4 changes: 4 additions & 0 deletions integration/combination/test_function_with_mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def companion_stack_outputs(self, get_companion_stack_outputs):
]
)
def test_function_with_mq(self, file_name, mq_broker, mq_secret, subnet_key):
# Temporarily skip this test and we should either re-enable this once the AZ issue is fixed
# or once we figure out a way to trigger integ test only when transform output changes.
if subnet_key == "PreCreatedSubnetOne":
pytest.skip("Skipping this test to temporarily bypass AvailabilityZone issue.")
companion_stack_outputs = self.companion_stack_outputs
parameters = self.get_parameters(companion_stack_outputs, subnet_key)
secret_name = mq_secret + "-" + generate_suffix()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"LogicalResourceId": "HelloLambda",
"ResourceType": "AWS::Lambda::Function"
},
{
"LogicalResourceId": "HelloLambdaRole",
"ResourceType": "AWS::IAM::Role"
},
{
"LogicalResourceId": "AppSyncApi",
"ResourceType": "AWS::AppSync::GraphQLApi"
},
{
"LogicalResourceId": "ApiKey",
"ResourceType": "AWS::AppSync::ApiKey"
},
{
"LogicalResourceId": "ApiSchema",
"ResourceType": "AWS::AppSync::GraphQLSchema"
},
{
"LogicalResourceId": "AppSyncLambdaDataSource",
"ResourceType": "AWS::AppSync::DataSource"
},
{
"LogicalResourceId": "TriggerFunction",
"ResourceType": "AWS::Lambda::Function"
},
{
"LogicalResourceId": "TriggerFunctionRole",
"ResourceType": "AWS::IAM::Role"
},
{
"LogicalResourceId": "AppSyncApiLambdaInvocationRole",
"ResourceType": "AWS::IAM::Role"
},
{
"LogicalResourceId": "DataSourceToLambdaConnectorPolicy",
"ResourceType": "AWS::IAM::ManagedPolicy"
},
{
"LogicalResourceId": "AppSyncSayHelloResolver",
"ResourceType": "AWS::AppSync::Resolver"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,13 @@
{
"LogicalResourceId": "DataSourceToTableConnectorPolicy",
"ResourceType": "AWS::IAM::ManagedPolicy"
},
{
"LogicalResourceId": "SaveNoteResolver",
"ResourceType": "AWS::AppSync::Resolver"
},
{
"LogicalResourceId": "GetNoteResolver",
"ResourceType": "AWS::AppSync::Resolver"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
Resources:
AppSyncApiLambdaInvocationRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: appsync.amazonaws.com
Action:
- sts:AssumeRole

HelloLambda:
Type: AWS::Serverless::Function
Properties:
InlineCode: |
exports.handler = async (_) => {
return "Hello World"
}
Handler: index.handler
Runtime: nodejs14.x

AppSyncApi:
Type: AWS::AppSync::GraphQLApi
Properties:
AuthenticationType: API_KEY
Name: AppSyncApi

ApiSchema:
Type: AWS::AppSync::GraphQLSchema
Properties:
ApiId: !GetAtt AppSyncApi.ApiId
Definition: |
type Query {
sayHello: String!
}
schema {
query: Query
}
AppSyncLambdaDataSource:
Type: AWS::AppSync::DataSource
Properties:
ApiId: !GetAtt AppSyncApi.ApiId
Name: AppSyncLambdaDataSource
Type: AWS_LAMBDA
ServiceRoleArn: !GetAtt AppSyncApiLambdaInvocationRole.Arn
LambdaConfig:
LambdaFunctionArn: !GetAtt HelloLambda.Arn

AppSyncSayHelloResolver:
DependsOn: ApiSchema
Type: AWS::AppSync::Resolver
Properties:
ApiId: !GetAtt AppSyncApi.ApiId
TypeName: Query
FieldName: sayHello
DataSourceName: !GetAtt AppSyncLambdaDataSource.Name
RequestMappingTemplate: |
{
"version" : "2017-02-28",
"operation": "Invoke",
"payload": $util.toJson($context.args)
}
ResponseMappingTemplate: |
$util.toJson($context.result)
DataSourceToLambdaConnector:
Type: AWS::Serverless::Connector
Properties:
Source:
Id: AppSyncLambdaDataSource
Destination:
Id: HelloLambda
Permissions:
- Write

ApiKey:
Type: AWS::AppSync::ApiKey
Properties:
ApiId: !GetAtt AppSyncApi.ApiId

TriggerFunction:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
API_KEY: !GetAtt ApiKey.ApiKey
GRAPHQL_URL: !GetAtt AppSyncApi.GraphQLUrl
Runtime: nodejs14.x
Handler: index.handler
InlineCode: |
const https = require("https");
exports.handler = async (_) => {
const queries = {
sayHello: /* GraphQL */ `
query {
sayHello
}
`,
};
const fetch = async (url, options) =>
new Promise((resolve, reject) => {
const req = https.request(url, options, (res) => {
const body = [];
res.on("data", (chunk) => body.push(chunk));
res.on("end", () => {
const resString = Buffer.concat(body).toString();
resolve(resString);
});
});
req.on("error", (err) => {
reject(err);
});
req.on("timeout", () => {
req.destroy();
reject(new Error("Request time out"));
});
req.write(options.body);
req.end();
});
const makeRequest = async (queryName) => {
const options = {
method: "POST",
headers: {
"x-api-key": process.env.API_KEY,
},
body: JSON.stringify({ query: queries[queryName] }),
timeout: 10000, // ms
};
const response = await fetch(process.env.GRAPHQL_URL, options);
const body = JSON.parse(response);
const data = body.data?.[queryName];
if (body.errors !== undefined) {
throw JSON.stringify(body.errors);
}
if (data !== "Hello World") {
throw new Error(`${queryName} error: '${data}' must be 'Hello World'`);
}
return body.data;
};
return await makeRequest("sayHello");
};
Metadata:
SamTransformTest: true
Loading

0 comments on commit c916e66

Please sign in to comment.