Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{
Effect: 'Allow',
Action: ['appsync:GraphQL'],
Resource: newPolicyResources,
},
],
},
});
for (const resource of resources) {
// We always have 2 parts, no need to check
const resourceParts = resource.split('/');
if (resourceParts[1] !== 'null') {
policyResources.push(
Fn.Sub('arn:aws:appsync:${AWS::Region}:${AWS::AccountId}:apis/${apiId}/types/${typeName}/fields/${fieldName}', {
apiId: {
'Fn::GetAtt': ['GraphQLAPI', 'ApiId'],
},
typeName: resourceParts[0],
fieldName: resourceParts[1],
})
);
resourceSize += RESOURCE_OVERHEAD + resourceParts[0].length + resourceParts[1].length;
} else {
policyResources.push(
Fn.Sub('arn:aws:appsync:${AWS::Region}:${AWS::AccountId}:apis/${apiId}/types/${typeName}/*', {
apiId: {
'Fn::GetAtt': ['GraphQLAPI', 'ApiId'],
},
typeName: resourceParts[0],
export function lambdaArnResource(name: string, region?: string) {
const substitutions = {};
if (referencesEnv(name)) {
substitutions['env'] = Fn.Ref(ResourceConstants.PARAMETERS.Env);
}
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Sub(lambdaArnKey(name, region), substitutions),
Fn.Sub(lambdaArnKey(removeEnvReference(name), region), {})
);
}
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Action: [
'dynamodb:BatchGetItem',
'dynamodb:BatchWriteItem',
'dynamodb:PutItem',
'dynamodb:DeleteItem',
'dynamodb:GetItem',
'dynamodb:Scan',
'dynamodb:Query',
'dynamodb:UpdateItem',
],
Resource: [
Fn.Sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}', {
tablename: SyncResourceIDs.syncTableName,
}),
Fn.Sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}/*', {
tablename: SyncResourceIDs.syncTableName,
}),
],
},
],
},
}),
],
});
}
export function syncLambdaArnResource({ name, region }: { name: string; region?: string }) {
private replaceEnv(value: string): Value {
if (!this.referencesEnv(value)) {
return value;
}
return Fn.Sub(value, {
env: Fn.Ref(ResourceConstants.PARAMETERS.Env),
});
}
Effect: 'Allow',
Action: [
'dynamodb:BatchGetItem',
'dynamodb:BatchWriteItem',
'dynamodb:PutItem',
'dynamodb:DeleteItem',
'dynamodb:GetItem',
'dynamodb:Scan',
'dynamodb:Query',
'dynamodb:UpdateItem',
],
Resource: [
Fn.Sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}', {
tablename: SyncResourceIDs.syncTableName,
}),
Fn.Sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}/*', {
tablename: SyncResourceIDs.syncTableName,
}),
],
},
],
},
}),
],
});
}
export function syncLambdaArnResource({ name, region }: { name: string; region?: string }) {
export function syncLambdaArnResource({ name, region }: { name: string; region?: string }) {
const env = 'env;';
const substitutions = {};
if (referencesEnv(name)) {
substitutions[env] = Fn.Ref(ResourceConstants.PARAMETERS.Env);
}
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Sub(lambdaArnKey(name, region), substitutions),
Fn.Sub(lambdaArnKey(removeEnvReference(name), region), {})
);
}
export function lambdaArnKey(name: string, region?: string) {
export function syncLambdaArnResource({ name, region }: { name: string; region?: string }) {
const env = 'env;';
const substitutions = {};
if (referencesEnv(name)) {
substitutions[env] = Fn.Ref(ResourceConstants.PARAMETERS.Env);
}
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Sub(lambdaArnKey(name, region), substitutions),
Fn.Sub(lambdaArnKey(removeEnvReference(name), region), {})
);
}
export function lambdaArnKey(name: string, region?: string) {
const resTemplate = print(ref('utils.toJson($utils.rds.toJsonObject($ctx.result)[0])'));
fs.writeFileSync(`${this.resolverFilePath}/${reqFileName}`, reqTemplate, 'utf8');
fs.writeFileSync(`${this.resolverFilePath}/${resFileName}`, resTemplate, 'utf8');
let resolver = new AppSync.Resolver({
ApiId: Fn.Ref(ResourceConstants.PARAMETERS.AppSyncApiId),
DataSourceName: Fn.GetAtt(ResourceConstants.RESOURCES.RelationalDatabaseDataSource, 'Name'),
TypeName: queryTypeName,
FieldName: fieldName,
RequestMappingTemplateS3Location: Fn.Sub(s3BaseUrl, {
[ResourceConstants.PARAMETERS.S3DeploymentBucket]: Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentBucket),
[ResourceConstants.PARAMETERS.S3DeploymentRootKey]: Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentRootKey),
[resolverFileName]: reqFileName,
}),
ResponseMappingTemplateS3Location: Fn.Sub(s3BaseUrl, {
[ResourceConstants.PARAMETERS.S3DeploymentBucket]: Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentBucket),
[ResourceConstants.PARAMETERS.S3DeploymentRootKey]: Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentRootKey),
[resolverFileName]: resFileName,
}),
}).dependsOn([ResourceConstants.RESOURCES.RelationalDatabaseDataSource]);
return resolver;
}
}
public updateResolverResource(resource: Resource) {
resource.Properties.RequestMappingTemplateS3Location = Fn.Sub(
's3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/${ResolverFileName}',
{
S3DeploymentBucket: Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentBucket),
S3DeploymentRootKey: Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentRootKey),
ResolverFileName: Fn.Join('.', [resource.Properties.TypeName, resource.Properties.FieldName, 'req', 'vtl']),
}
);
resource.Properties.ResponseMappingTemplateS3Location = Fn.Sub(
's3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/${ResolverFileName}',
{
S3DeploymentBucket: Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentBucket),
S3DeploymentRootKey: Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentRootKey),
ResolverFileName: Fn.Join('.', [resource.Properties.TypeName, resource.Properties.FieldName, 'res', 'vtl']),
}
);
delete resource.Properties.RequestMappingTemplate;
delete resource.Properties.ResponseMappingTemplate;
return resource;
}